Home Answers Viewqa Java-Beginners cannot find symbol method nextchar()??

 
 


anna ellen
cannot find symbol method nextchar()??
1 Answer(s)      2 years and 2 months ago
Posted in : Java Beginners

import java.util.Scanner; public class Calc5{ public static void main(String args[]){ Scanner obj = new Scanner(System.in); System.out.println("please enter operand1, operand2 and operator(+,-,x,/)"); int a = obj.nextInt(); int b = obj.nextInt(); double c ; char op = obj.nextChr ();

                if(op == '+'); 
                c = a+b;
                    System.out.println ("a" +"+"+ "b");
                    System.out.println("the result is=" + c);

                if (op == '-');
                c = a-b;
                    System.out.println ("operand1" +"-"+ "operand2");
                    System.out.println("the result is=" + c);

                 if  (op == '/') ;
                c= a/b;
                       System.out.println ("operand1" +"/"+ "operand2");
                       System.out.println("the result is=" + c);

                if (op == '*'); 
                c = a * b;
                    System.out.println ("operand1" +"x"+ "operand2");
                    System.out.println ("the result is=" +c);

} // end of main

} // end of class

View Answers

March 14, 2011 at 11:27 AM


import java.util.Scanner; 
public class Calc5{
    public static void main(String args[]) throws Exception{
        Scanner obj = new Scanner(System.in);
        System.out.println("please enter operand1: ");
        int a = obj.nextInt();
        System.out.println("please enter operand2: ");
        int b = obj.nextInt();
        double c ;
        System.out.println("please enter operator(+,-,x,/): ");
        char op = (char)System.in.read();
                if(op == '+'){
                c = a+b;
                    System.out.println ("a" +"+"+ "b");
                    System.out.println("the result is=" + c);
                }
                else if (op == '-'){
                c = a-b;
                    System.out.println ("operand1" +"-"+ "operand2");
                    System.out.println("the result is=" + c);
                }
                 else if  (op == '/'){
                c= a/b;
                       System.out.println ("operand1" +"/"+ "operand2");
                       System.out.println("the result is=" + c);
                 }
                else if (op == '*'){
                c = a * b;
                    System.out.println ("operand1" +"x"+ "operand2");
                    System.out.println ("the result is=" +c);
                }
} 
}









Related Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.