Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to convert char to int in Java

5 Answers

0 votes
public class MyClass {
    public static void main(String args[]) {
        char ch = 'z'; 
        
        int n = (int)ch;
        
        System.out.println(n);
    }
}




/*
run:

122

*/

 





answered Apr 3, 2021 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        char ch = '5'; 
         
        int n = ch - '0';
         
        System.out.println(n);
    }
}
 
 
 
 
/*
run:
 
5
 
*/

 





answered Apr 3, 2021 by avibootz
edited Oct 13, 2023 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        char ch = '7'; 
        
        int n = Integer.parseInt(ch + "");
        
        System.out.println(n);
    }
}




/*
run:

7

*/

 





answered Apr 3, 2021 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        char ch = '5'; 
         
        int n = Character.getNumericValue(ch);
         
        System.out.println(n);
    }
}
 
 
 
 
/*
run:
 
5
 
*/

 





answered Oct 13, 2023 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        char ch = '9'; 
         
        int n = Character.digit(ch, 10);
         
        System.out.println(n);
    }
}
 
 
 
 
/*
run:
 
9
 
*/

 





answered Oct 13, 2023 by avibootz

Related questions

1 answer 59 views
1 answer 62 views
62 views asked Jan 20, 2021 by avibootz
1 answer 93 views
93 views asked Nov 5, 2018 by avibootz
1 answer 96 views
...