- 1
what we takes input for strings inSystem.in that we are taking integer input.syntax is a=nextInt(System.in).whats about strings
5 Answers
+ 4
You can get user input char by char, by setup your scanner object, and then use the next() method:
import java.util.Scanner;
public class Program {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
sc.useDelimiter("");
int i = 10;
while (i-->0) {
System.out.println(sc.next());
}
}
}
... but remember that the keyboard stream is buffered by OS, and will be released only when user press the 'enter' ('return') key ^^ So, if your purpose is to listen for user key press, you need to handle it by another way ;P
+ 2
next() or nextLine()
+ 1
I don't think so.There is no method for character.
0
this is for character
- 1
THANKS