Using Netbeans IDE Javascript You will be implementing a simple command line app
ID: 3785699 • Letter: U
Question
Using Netbeans IDE Javascript
You will be implementing a simple command line application that prompts the user for a name, and prints it in "Bond, James Bond" form. Your application class should be called Bond java. Requirements As you probably know, in most James Bond movies he introduces himself at some point as "Bond, James Bond". Your program should turn any name entered by the user into a string in this form. For example: Enter a name John Sullins Sullins, John Sullins Note that the last space in the string entered should be the one used to break the name up. For example: Enter a name: James T. Kirk Kirk, James T Kirk Finally, if the name entered contains no spaces, the output should be in the format "name, just name". For example: Enter a name Yoda Yoda, just YodaExplanation / Answer
import java.util.Scanner;
public class TestConsole {
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.print("Enter a name:");
String ss = s.nextLine();
String last=ss.substring(ss.lastIndexOf(" ")+1);
if(ss!=last)
System.out.println(last+","+ss);
else
System.out.println(ss+","+"just"+" "+ss);
}
}