7.WAP to print details about you i.e., your name and age using VARIABLE IN JAVA only.
Answers
Answered by
4
With Scanner Class your answer will be:
import java.util.*;
class program
{
void main ()
{
Scanner ob = new Scanner (System.in);
String n, a;
System.out.println("Enter your name");
n = ob.nextLine();
System.out.println("Enter your age");
a = ob.nextLine();
System.out.println("Your name is " + n);
System.out.println("Your age is " + a);
}
}
Without Scanner Class your answer will be:
class program
{
void main (String a, String n)
{
System.out.println("Your name is " + n);
System.out.println("Your age is " + a);
}
}
import java.util.*;
class program
{
void main ()
{
Scanner ob = new Scanner (System.in);
String n, a;
System.out.println("Enter your name");
n = ob.nextLine();
System.out.println("Enter your age");
a = ob.nextLine();
System.out.println("Your name is " + n);
System.out.println("Your age is " + a);
}
}
Without Scanner Class your answer will be:
class program
{
void main (String a, String n)
{
System.out.println("Your name is " + n);
System.out.println("Your age is " + a);
}
}
Answered by
7
Answer:
public class Test
{
void display ( )
{
String name = "Angel" ;
int age = 18 ;
System.out.println ("My name is " + name) ;
System.out.println ("My age is" + age) ;
}
}
Output produced is:
My name is Angel
My age is 18
Variable :
a variable is a named memory location, Which holds the data value of a particular data type
Similar questions
Computer Science,
7 months ago
Physics,
1 year ago
Math,
1 year ago
History,
1 year ago
Math,
1 year ago