+ 3

How can I scan a single input char in Java

like I want to enter an operator eg the the plus Sign +

8th Oct 2017, 1:29 PM
duncan123
6 odpowiedzi
+ 7
i can't underatnd what u want to ask //plzz explain
8th Oct 2017, 1:47 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 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 ☺
8th Oct 2017, 1:58 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 5
you can use: next.charAt(0); 😊
8th Oct 2017, 6:09 PM
Cool Codin
Cool Codin - avatar
+ 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!?
8th Oct 2017, 1:53 PM
duncan123
+ 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.
8th Oct 2017, 1:54 PM
Shreyas Dixit
Shreyas Dixit - avatar
+ 1
Also we can always use switch. List all the operators in the cases and match them and perform the required operation.
8th Oct 2017, 2:23 PM
Shreyas Dixit
Shreyas Dixit - avatar