8. Write a sequence of Java statements to match the description in the following
ID: 3664359 • Letter: 8
Question
8. Write a sequence of Java statements to match the description in the following comments: //declare a String variable to represent the user’s surname //and another String variable to represent the user’s other name //prompt the user for his/her surname, and then input a value for the surname //prompt the user for his/her other name, and then input a value for the other name //output a message of a form: Hello x! You belong to the y family //where x is the value of the other name variable, and y is the value of the surname variable
Explanation / Answer
<code>
import java.util.Scanner;
public class rand {
public static void main(String[]args){
Scanner in = new Scanner(System.in);
String userSurname;
String userOtherName;
String othername;
System.out.print("Surname:");
userSurname = in.nextLine();
System.out.println("OtherName");
userOtherName = in.nextLine();
System.out.println("Hello "+userOtherName+"! You belong to the "+userSurname+" family");
}
}
</code>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.