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 221 views
1 answer 198 views
2 answers 326 views
326 views asked May 29, 2020 by avibootz
1 answer 197 views
1 answer 210 views
3 answers 289 views
1 answer 289 views
...