0
Java Exception
package learn2; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner (System.in); System.out.println("Enter your name "); String name = input.nextLine(); // I entered No. 2 , and still working. why there is no exception here !!!!!! System.out.println("You are welcome "); } } // Why the code is executed even if I put an int. I declared the variable name as a string.
1 Antwort
+ 1
2 is read in as a string. So there is no exception. Also, 2 is a valid string.