Question: (THE FOLLOWING IS A JAVA CODE) public class Homework { public static void main(String[] args) { String name; String id; double score; Scanner a =
(THE FOLLOWING IS A JAVA CODE)
public class Homework {
public static void main(String[] args)
{
String name;
String id;
double score;
Scanner a = new Scanner(System.in);
System.out.println("Please enter your name: ");
name=a.nextLine();
if( !(name.length() >1 &&name.contains((","))==true))
{
System.out.println("Please enter your name like LastName, FirstName: ");
name=a.nextLine();
name=name.replace(","," ");
}
name=name.replace(","," ");
System.out.println("Please enter your ID without any spaces: ");
id=a.nextLine();
if(!(id.length()==7))
{
System.out.println("Please enter your ID without any spaces: (7 digits) ");
id=a.nextLine();
}
System.out.println(" Please enter your score: ");
score=a.nextInt();
if(!(score>=0 && score <=100))
{
System.out.println(" Please enter your score: with range 0 10 100");
score=a.nextInt();
}
System.out.println(name +" got "+ score +"!");
}
}
Currently, the output looks like this:
Please enter your name:
Sparrow, Jack
Please enter your ID without any spaces:
1234567
Please enter your score:
100
Sparrow Jack got 100.0!
I need it to look like this:
Please enter your name:
Sparrow, Jack
Please enter your ID without any spaces:
1234567
Please enter your score:
100
Jack Sparrow got 100.0!
How do I replace the last name and the first name in the output of my code?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
