+ 3
How can I scan a single input char in Java
like I want to enter an operator eg the the plus Sign +
6 ответов
+ 7
i can't underatnd what u want to ask
//plzz explain
+ 7
//i got an another idea
u can post comment in ur code that enter 2 number separated by some space , enter 1 for sum , 2 for substraction , 3 for multiplication , 4 for division
ie , inout ::: 2 4 1 ===>>>outputs :::2+4= 8
//example :::
Scanner sc=new Scanner (System.in);
int a=sc.nextInt ();
int b=sc.nextInt ();
int c=sc.nextInt ();
if (c==1)
System.out.print (a "+" b+ "="a+b);
//u can complete the code now ☺
+ 5
you can use: next.charAt(0);
😊
+ 2
I want a user to enter two numbers then again to enter an operator (+ ,- , *, / ) such as
Enter two numbers: 12 15
Enter an operator : +
12 + 15 = 27
Qn: I used nextInt() to scan 12 and 15
what do I use to scan the + sign!?
+ 1
We can use next() from Scanner class. It is basically used to accept single line strings but it can also be used to accept single characters.
Maybe there is a method in BufferedReader class, I'm not aware of it though as I don't use it much.
+ 1
Also we can always use switch. List all the operators in the cases and match them and perform the required operation.