Question: Can you put this in a while loop. import java.util.Scanner; public class Test1 { public static void main(String args[]) { Scanner sc = new Scanner(System.in);

Can you put this in a while loop.

import java.util.Scanner;

public class Test1 {

public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println(); System.out.print("Customer Name (Last, First) > "); String name = sc.nextLine().trim(); String names[] = name.split(", ");

//Checking user enter both the names if (names.length == 2 && names[0].length() != 0 && names[1].length() != 0) { //Validating last name for (int i = 0; i < names[0].length(); i++) { if (i == 0) { //Checking first char is upper case if (!(names[0].charAt(0) >= 'A' && names[0].charAt(0) <= 'Z')); System.out.println("Invalid input"); if (!(names[0].charAt(i) >= 'a' && names[0].charAt(i) <= 'z')) { return; }

} }

//Checking same for the first name for (int i = 0; i < names[1].length(); i++) { if (i == 0) { //Checking first char is upper case if (!(names[1].charAt(0) >= 'A' && names[1].charAt(0) <= 'Z')) { return; } } else { //Checking all other character other than first char is lower case if (!(names[1].charAt(i) >= 'a' && names[1].charAt(i) <= 'z')) { return; } } } } else { System.out.println("Fallow Correct Format"); }

}

}

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!