int n ;
n= (int)( javax.swing.JOptionPane.showInputDialog(null,"enter a 3 digit no."));
Why does the above gives error[required int, found string] and the below one works fine ?
int n ;
n= Integer.parseInt( javax.swing.JOptionPane.showInputDialog(null,"enter a 3 digit no."));
Integer.parseIntdoesn’t use casting but rather a simple algorithm to interpret the digits in the string as a number. Casting is done by the JVM directly on the primitive value or the compiler on the object reference. It can turn4.5into4(type conversion as it changes the underlying value) andArrayListintoList(reference casting as it doesn’t modify the instance), but it cannot parse or format numbers natively.