char cannot be dereferenced
807601May 11 2008 — edited May 11 2008I 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.");
}
}