The program should ask the user to enter (use the Scannerclass) the following: -
ID: 3608627 • Letter: T
Question
The program should ask the user to enter (use the Scannerclass)the following:
- His or her first name
- His or her middle name
- His or her last name
- His or her age
- His or her lucky number
- His or her favorite color
If the user's name was Not Too Young,
the output of the program should be as follows.
% java Assignment2
A story about Not Too Young:
NOT TOO YOUNG is NTY.
NTY's favorite color is red, and NotY. is 23.
The lucky number of N. T. Young is77.
The program should ask the user to enter (use the Scannerclass)
the following:
- His or her first name
- His or her middle name
- His or her last name
- His or her age
- His or her lucky number
- His or her favorite color
If the user's name was Not Too Young,
the output of the program should be as follows.
% java Assignment2
A story about Not Too Young:
NOT TOO YOUNG is NTY.
NTY's favorite color is red, and NotY. is 23.
The lucky number of N. T. Young is77.
Explanation / Answer
import java.util.Scanner;public class GetInput{public static void main(String[] args) {String fn,mn,ln,lucky_num,fav_color,string;int age;Scanner keyboard = new Scanner(System.in);System.out.println("Enter first name ");string = keyboard.next();fn=string;System.out.println("Enter middle name ");string = keyboard.next();mn=string;System.out.println("Enter last name ");string = keyboard.next();ln=string;System.out.println("Enter age ");age= keyboard.nextInt();System.out.println("Enter lucky num ");string = keyboard.next();lucky_num = string;System.out.println("Enter fav color ");string = keyboard.next();fav_color=string;if(age > 13 ){ System.out.println("NOT TOO YOUNG is " + fn.charAt(0) + mn.charAt(0) + ln.charAt(0));System.out.println(fn.charAt(0) + mn.charAt(0) + ln.charAt(0)+"'s favorite color is "+ fav_color+ ", and Not "+ ln.charAt(0)+" is "+age+".");System.out.println("The lucky number of " + fn.charAt(0) + mn.charAt(0) + ln.charAt(0) + "'s is " + lucky_num + " Young is " +age);}elseSystem.out.println("TOO YOUNG is " +fn.charAt(0) + mn.charAt(0));}}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.