Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

Have Programming Question? Ask it here!
 
 
 


anna ellen
cannot find symbol method nextchar()??
1 Answer(s)      3 years and 5 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


Advertisement
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 Tutorials/Questions & Answers:
 

 

 

DMCA.com