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.

1 answer

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!”);
}
}
Similar Questions
  1. Hi,I have to write a method that returns my first name, middle initial, and last name as a single String and call the method in
    1. answers icon 2 answers
    1. answers icon 1 answer
    1. answers icon 4 answers
  2. PLZ HELP ASAP1. What is Java SE? A. Java Standard Edition B. Java Software Editor C. Java Scientific Edition D. Java Software
    1. answers icon 2 answers
more similar questions