import java.util.Scanner;
public class stringToNum{
public static void main(String[] args) throws Exception{
String number;
int num = 0;
Scanner input = new Scanner(System.in);
System.out.println("Enter any Number");
try{
number = input.next();
num = Integer.parseInt(number);
System.out.println(num);
}catch(Exception e){
System.out.println("You have to enter a number");
}
}
}
No comments:
Post a Comment