Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started