How to get the third digit of a number in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        int number = 87354;
        String s = String.valueOf(number);
        
        char ch = s.charAt(2);
        System.out.println(ch);
        
        int x = s.charAt(2) - '0';
        System.out.println(x);
    }
}



/*
run:

3
3

*/

 



answered Jun 1, 2020 by avibootz

Related questions

1 answer 139 views
1 answer 105 views
2 answers 190 views
190 views asked May 29, 2020 by avibootz
1 answer 100 views
1 answer 118 views
3 answers 130 views
1 answer 179 views
...