Asked by De

Write a Java program that prompts the user for a string. If the string entered by the user does not start with Hello and does not end with a digit, print incorrect and re-prompt the user. Otherwise, print Thank you.

Answers

Answered by shehab
import java.util.Scanner;
public class ReviewQuestion4 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print(“Enter string: “);
String input = keyboard.nextLine();
while (input.length() < 5 ||
!input.substring(0,5).equals(“Hello”) ||
!Character.isDigit(input.charAt(input.length()-1))) {
System.out.println(“Incorrect.”);
System.out.print(“Enter string: “);
input = keyboard.nextLine();
}
System.out.println(“Thank you!”);
}
}
There are no AI answers yet. The ability to request AI answers is coming soon!

Related Questions