Single digit displaying after entering double digit as input in java Program -
in below java code if entering double digit input getting value entered single digit.i think problem & num variable of diff data types. 2.if taking num int value entered converted different value. entered 20 & took 50. please help.
class primenumber { public static void main(string args[]) throws java.io.ioexception{ system.out.println("enter number test prime number"); char num; num=(char)system.in.read(); system.out.println("number entered "+num); boolean tarun =true; for(int i=2;i<=num/i;i++){ if(num%i==0){ tarun=false; break; } } if(tarun) system.out.println(num +" prime number"); else system.out.println(num +" not prime number "); } }
`output:- enter number test prime number 22 number entered 2 2 not prime number
num=(char)system.in.read();
you casting number character? why this?
since num
a... number, this:
int num; num = system.in.read();