Answer to Question #336403 in Java | JSP | JSF for Dreaper

Question #336403

Create a Java program in jdoodle that will determine if the score is Passed/Failed. (10 is the passing score out of 20)

  • Will not accept special characters.
  • will not accept blank score.
  • will not accept if it's greater than 20.
  • will not accept if it's lesser than 1.
1
Expert's answer
2022-05-02T14:45:44-0400
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!");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS