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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.