0

Show me a program to display the first digit of a number taken as input.

2nd Jan 2017, 5:07 PM
Anand Chourasiya
Anand Chourasiya - avatar
3 Antworten
+ 2
int number = scanner.nextInt(); System.out.println((""+number).charAt(0));
2nd Jan 2017, 5:18 PM
Uran Kajtazaj
Uran Kajtazaj - avatar
+ 1
(""+number) converts the input which is an int, to a string. .charAt(0) gets the first character. input: 4203 output: 4
4th Jan 2017, 11:22 AM
Uran Kajtazaj
Uran Kajtazaj - avatar
0
Can you explain it?
4th Jan 2017, 8:33 AM
Anand Chourasiya
Anand Chourasiya - avatar