How to get the N digit of a number in Java

1 Answer

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



/*
run:

5
5

*/

 



answered Jun 1, 2020 by avibootz

Related questions

1 answer 137 views
2 answers 161 views
1 answer 115 views
2 answers 159 views
1 answer 125 views
1 answer 127 views
...