Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions