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

Using Java: Ask the user to the enter their name (static variable) and age (inte

ID: 3662906 • Letter: U

Question

Using Java:

Ask the user to the enter their name (static variable) and age (interger variable)

I am using the code below and I believe I am doing something wrong with the string variable but can not figure it out.

import java.until.Scanner;

public class user
{
   public static void main(String[] args)
   {
   Scanner input = new Scanner(System.in);

String firstName
int age

Scanner input = new Scanner (System.in);
System.out.print("Enter your name: ");
System.out.print("Enter your age: ");

System.out.printf("Data: ", firstName, age);
   }
}

Explanation / Answer

Program:

import java.util.Scanner;

public class user
{
   private static String firstName;
   private static Scanner input;
public static void main(String[] args)
{
   input = new Scanner(System.in);
   int age;
System.out.print("Enter your name: ");
firstName=input.next();
System.out.print("Enter your age: ");
age=input.nextInt();
System.out.printf("Data: "+ firstName+" " + age);
}
}

Result:

Enter your name: John
Enter your age: 24
Data: John 24

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote