Answered step by step
Verified Expert Solution
Link Copied!

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: );

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

2. Do you exercise? yes no

Answered: 1 week ago

Question

Consider this article:...

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago