I need help making a java code. Write a program that prompts the user to enter a social security number in the format DDD-DD-DDDD, where D is a digit. The program should check if the input is valid. If the program isn't valid I need to provide 1 of 3 feedback. 1"You entered an invalid social security number." 20%" 2 "Can't you follow directions? 40%" 3. "You are not very smart are you?" 40% I need 1 to come 20% of the time, and 2 and 3 40% I need random number gen used to select the response. I keep getting an error saying java: reached end of file while parsing
I need help making a java code. Write a program that prompts the user to enter a social security number in the format DDD-DD-DDDD, where D is a digit. The program should check if the input is valid. If the program isn't valid I need to provide 1 of 3 feedback.
1"You entered an invalid social security number." 20%"
2 "Can't you follow directions? 40%"
3. "You are not very smart are you?" 40%
I need 1 to come 20% of the time, and 2 and 3 40% I need random number gen used to select the response.
I keep getting an error saying java: reached end of file while parsing
import java.util.Scanner;
public class security_number
{
public static void main (String [] args)
{
Scanner in= new Scanner (System.in);
System.out.print("Enter social security number:");
String s= in.nextLine();
boolean isValid = (s.length==11) && ( Character.isDigit(s.charAt(0))) && (Character.isDigit(s.charAt(1))) && (Character.isDigit(s.charAt(2))) && (s.charAt(3)== '-' ) && (Character.isDigit(s.charAt(4))) && (Character.isDigit(s.charAt(5))) && (s.ChatAt(6)=='-') && (Character.isDigit(s.charAt(7))) && (Character.isDigit(s.charAt(8))) && (Character.isDigit(s.charAt(9))) &&
(Character.isDigit(s.charAt(10)));
if(isValid)
{
System.out.println("You entered valid social security number");
}
else
{
System.out.println("You entered an invalid social security number");
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps