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 154 views
2 answers 177 views
1 answer 131 views
2 answers 176 views
1 answer 144 views
1 answer 142 views
...