+ 1

How can I scan a character in java?

1st Jul 2019, 9:52 AM
Ahmed Mostafa
Ahmed Mostafa - avatar
4 Réponses
+ 1
Scanner sc = new Scanner(System.in); char myChar = sc.next().charAt(0); System.out.println(myChar);
1st Jul 2019, 3:07 PM
HNNX 🐿
HNNX 🐿 - avatar
+ 3
import java.util.Scanner; //in main method create an object of Scanner Scanner sc = new Scanner(System.in); //Read input and assign it to a variable of type String str = sc.nextLine(); //or int i = sc.nextInt(); System.out.print(str);
1st Jul 2019, 10:08 AM
D_Stark
D_Stark - avatar
+ 1
Anhjje 🐿 thank you 😊
1st Jul 2019, 3:12 PM
Ahmed Mostafa
Ahmed Mostafa - avatar
0
I mean one character not string char x; How can I make the user enter the value of this x
1st Jul 2019, 12:15 PM
Ahmed Mostafa
Ahmed Mostafa - avatar