Assessment 4 Notes
Assessment 4 Notes
import java.lang.NumberFormatException;
import java.util.Scanner;
try {
int n = Integer.parseInt(num);
a=false;
break;
}
catch (NumberFormatException e) {
System.out.println("Not an integer value");
s.nextLine();
}
}
while(a==true);
}
}
package Assessment_4_NumberFormatException;
import java.util.Scanner;
try {
int n = Integer.parseInt(num);
if(n<10||n>20){
System.out.println("Number entered is out of
limits");
s.nextLine();
}
else {
a = false;
System.out.println("The entered number is "+num);
break;
}
}
catch (NumberFormatException e) {
System.out.println("Not an integer value");
s.nextLine();
}
}
while(a==true);
}
}
package Assessment_4_InputMismatchException;
import java.util.InputMismatchException;
import java.util.Scanner;
package Assessment_4_InputMismatchException;
import java.util.InputMismatchException;
import java.util.Scanner;
try {
int n = s.nextInt();
switch (n) {
case 1:
System.out.println("You have selected 1");
a=true;
break;
case 2:
System.out.println("You have selected 2");
a=true;
break;
case 3:
System.out.println("You have selected 3");
a=true;
break;
default:
System.out.println(" number not from 1 to 3");
s.nextLine();
}
} catch (InputMismatchException e) {
System.out.println("You have entered a non-integer value");
s.nextLine();
}
}while(a==false);
}
}
package Assessment_4_InputMismatchException;
import java.util.InputMismatchException;
import java.util.Scanner;
catch (InputMismatchException e) {
System.out.println("Enter a valid age");
s.nextLine();
}
}
while(a==false);
}
}