Write a java program that prompts the user to input a word from the keyboard representing a user id. If the length of the word is between six and ten characters, the program prints the user id. Otherwise, the program print the message “Invalid user id.”


Write a java program that prompts the user to input a word from the keyboard representing a user id. If the length
of the word is between six and ten characters, the program prints the user id. Otherwise, the program print
the message “Invalid user id.”

1 Answer

4 years ago by

Check output here

import java.util.*;  
class UserInputDemo1  
{  
public static void main(String[] args)  
{  
  Scanner sc= new Scanner(System.in); 
  System.out.print("Enter a string: ");  
  String str= sc.nextLine();                 
  if (str.length() > 6 && str.length() < 10) System.out.println(str);
  else System.out.println("Invalid username");
}  
}  
4 years ago by Divya