0
Show me a program to display the first digit of a number taken as input.
3 Antworten
+ 2
int number = scanner.nextInt();
System.out.println((""+number).charAt(0));
+ 1
(""+number) converts the input which is an int, to a string.
.charAt(0) gets the first character.
input: 4203
output: 4
0
Can you explain it?