Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the Scanner class to accept input from the user. Prompt the user for their f

ID: 3626933 • Letter: U

Question

Use the Scanner class to accept input from the user.
Prompt the user for their first name, last name, and age each individually.
Use string concatenation to obtain the user’s full name.
Use equals() and If their first and last name are the same print:
“Hello First Last, your first and last name are the same”
If your first and last name are different, print:
“Hello First Last, your first and last name are different”
Print the length of their first name and of their full name.
Use the charAt() method of the String class to find the user’s initials. Print these, followed by their ASCII value, in tabular format (see example)
Print out the name per example below.
Using increment, increase the age by one output per example below.
Using compound assignment operators, increase the age by 4 more and output the new age.

Explanation / Answer

import java.util.*;

class test
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter first name ");
String fname= in.nextLine();
System.out.println("Enter last name ");
String lname= in.nextLine();
System.out.println("Enter Age ");
int age= in.nextInt();
String fullname = fname + lname;
if(fname.equals(lname))
System.out.println("Hello " + fullname +",your first and last name are the same");
else
System.out.println("Hello " + fullname +",your first and last name are different");
System.out.println("intial in first name is " + fname.charAt(0) + " Ascii value is " + (int) fname.charAt(0) );
System.out.println("intial in last name is " + lname.charAt(0) + " Ascii value is " + (int) lname.charAt(0) );
System.out.println(" Age is "+ age);
age = age+1;
System.out.println(" After incrementing one ");
System.out.println(" Age is "+ age);
age+=4; // compound operator.
System.out.println(" After incrementing by four ");
System.out.println(" Age is "+ age);

}
}