Question: Use java Exceptions knowledge to solve this question. Code below: public static String getUserNameA() { Scanner scanner = new Scanner(System.in); System.out.println(Enter your user name: );

 Use java Exceptions knowledge to solve this question. Code below: public

Use java Exceptions knowledge to solve this question.

Code below:

 public static String getUserNameA() { Scanner scanner = new Scanner(System.in); System.out.println("Enter your user name: "); String name = scanner.next(); if (name.length() ==0) { throw new RuntimeException("User name must include at least one character."); } return name; } public static String getUserNameB() { Scanner scanner = new Scanner(System.in); System.out.println("Enter your user name: "); String name = scanner.next(); if (name.length() ==0) { throw new Exception("User name must include at least one character."); } return name; } 

QUESTION 5 Two static methods are listed below. Which of them needs a "throws" clause in order to compile? public static String getUserNameA0 Scanner scanner new Scanner(System.in); System.out.println( Enter your user name: " String name scanner.next0 if (name.length0) throw new RuntimeException("User name must include at least one character."); one character" return name public static String getUserNameB0 Scanner scanner new Scanner(System.in) System.out.println( Enter your user name: "; String name scanner.next0: if (name.length0 ) throw new Exception(User name must include at least one character."); return name; O getUserNameA O getUserNameB

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!