84.7k views
0 votes
Write some code that reads in a name as a string and an age as an integer into the variables name and age. It then prints the message "The age of NAME is AGE" on a line by itself, where NAME and AGE represent the values read into the variables name and age respectively. For example, if your code read in "Rohit" and 70 then it would print out "The age of Rohit is 70" on a line by itself. There should NOT be a period in the output. Use the up or down arrow keys to change the height.

User UmaN
by
4.2k points

1 Answer

7 votes

Answer:

Following are the code to this question:

import java.util.*;//import package

public class Main//defining class Main

{

public static void main(String[] as)//defining main method

{

Scanner obx= new Scanner(System.in);//creating Scanner class Object

String name = obx.next();//input String value in name variable

int age = obx.nextInt();//input integer value in age variable

System.out.println("The age of " + name + " is " + age);//print value with message

}

}

Output:

Rohit

70

The age of Rohit is 70

Step-by-step explanation:

The description of the given java code can be defined as follows:

  • In the above java code, two-variable "name and age " is declared, in which name is string variable and age is an integer variable.
  • In the next step, the scanner class object is created, in which we input values in the variable and use the print method to print its value with the message.
User Arets Paeglis
by
4.3k points