Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

char cannot be dereferenced

807601May 11 2008 — edited May 11 2008
I can't get this program to work, i keep getting that error on lines 21,23,35, and 27. Any tips? I want to allow the user to be able to input 2 numbers, and also choose what to do with those numbers. I'd appreciate small tips, I kinda want to figure it out on my own but after working on this for hours I'm getting too frustrated.

import java.util.*;

public class calc
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);

int n1, n2;
char op;

System.out.println("Enter the first number:");
n1 = keyboard.nextInt();

System.out.println("Enter the second number:");
n2 = keyboard.nextInt();

System.out.println("Enter the arithmetic operator:");
op = keyboard.nextLine().charAt(0);

if (op.equals("*"))
System.out.println("n1 * n2");
else if (op.equals("+"))
System.out.println("n1 + n2");
else if (op.equals("/"))
System.out.println("n1 / n2");
else if (op.equals("-"))
System.out.println("n1 - n2");
else
System.out.println("Not a valid symbol.");

}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 8 2008
Added on May 11 2008
5 comments
398 views