+ 1

What is for input of char in scanner cladd

find out

8th Sep 2017, 9:21 AM
SK Ali
SK Ali - avatar
3 Answers
+ 15
char a=n.next().charAt(0); Declare a Scanner name n or .. and use the above sentence.
8th Sep 2017, 9:57 AM
Nithiwat
Nithiwat - avatar
+ 4
The Scanner Class does not have a method that returns a char. You could use nextLine() to get a String and convert it to a char or call toCharArray() on it to get a char array and then loop over the chars in the array. import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); char[] characters = sc.nextLine().toCharArray(); for(char character: characters) { System.out.println(character); } } }
8th Sep 2017, 9:55 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
thanks friends for your support
8th Sep 2017, 10:37 AM
SK Ali
SK Ali - avatar