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
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