Create a Java program in jdoodle that will determine if the score is Passed/Failed. (10 is the passing score out of 20)
import java.util.Scanner;
public class Answer {
public static void main(String[] args) throws NumberFormatException{
Scanner scanner = new Scanner(System.in);
String ans;
String regex = "a-z~@#$%^&*:;<>.,/}{+";
System.out.println("Enter score :");
ans = scanner.nextLine();
while (ans.isBlank() || Integer.parseInt(ans) > 20 || Integer.parseInt(ans) < 1 || ans.contains(regex)) {
System.out.println("Enter score again!");
ans = scanner.nextLine();
}
if (Integer.parseInt(ans) >= 10) {
System.out.println("Passed!");
} else {
System.out.println("Failed!");
}
}
}
Comments
Leave a comment