1.
Write a program to print “National Public School , East” in one line and Your name & Your age in next line
import [Link]; public class Prg7
{
public static void main()
{
[Link]("National Public School East");
[Link]("Sreedevi R");
[Link]("12");
}
}
2. Declare three variables to store your name , class and section and print the same as a proper sentence .
import [Link];
public class Prg8
{
public static void main()
{
String name="James Gosling";
int c=7;
char s='B';
[Link]("My name is "+name+" I study in "+c+s);
}
}
3. WAP to store your name and age. Display the same and the age after 5 years in proper sentence .
import [Link];
public class Prg3
{
public static void main(String[] args)
{
String name="James Gosling";
int age=12;
int newage;
newage=age+5;
[Link]("My name is "+name+" I am "+age+" years old");
[Link](" I will be "+newage+"years old after 5 years");
}
}
4. Write a program to store two numbers, display the sum, difference, product and quotient .
import [Link];
public class Prg4
{
public static void main(String[] args)
{
int num1=7;
int num2=2;
int sum,diff,pro,quo;
sum = num1+num2;
diff=num1-num2;
pro=num1*num2;
quo=num1/num2;
[Link]("The two numbers are "+num1+" and "+num2);
[Link](" The result of addition"+ sum);
[Link](" The result of subtraction"+ diff);
[Link](" The result of multiplication"+ pro);
[Link](" The result of division"+ quo);
}
}
5. Write a program to store a number, display the square of given number.
import [Link];
public class Prg5
{
public static void main(String[] args)
{
int num1=7;
int sqr;
sqr=num1*num1;
[Link]("The square of the number "+num1+" is "+sqr);
}
}
6. WAP to assign three numbers and print the sum of three numbers.
import [Link];
public class Qtn3
{
public static void main(String[] args)
{
int a,b,c,d;
a=10;
b=18;
c=15;
d=a+b+c;
[Link](“The numbers are”+a+ “ ,”+b+ “ ,” +c);
[Link](“The sum is” + d);
}
}
7. WAP to accept three numbers and print the sum of three numbers
import [Link];
public class prg10
{
public static void main(String[] args)
{
Scanner sc= new Scanner([Link]); //[Link] is a standard input stream
[Link]("Enter first number- ");
int a= [Link]();
[Link]("Enter second number- ");
int b= [Link]();
[Link]("Enter third number- ");
int c= [Link]();
int d=a+b+c;
[Link]("Total= " +d);
}
}
8. WAP to accept a String value and print the same.
import [Link];
public class prg11
{
public static void main(String[] args)
{
Scanner sc= new Scanner([Link]); //[Link] is a standard input stream
[Link]("Enter a string: ");
String str= [Link](); //reads string
[Link]("You have entered: "+str);
}
}
9. Program to accept
import [Link];
public class prg11
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
// Reading a string
[Link]("Enter your name: ");
String name = [Link]();
// Reading an integer
[Link]("Enter your age: ");
int age = [Link]();
// Reading a double
[Link]("Enter your height: ");
double height = [Link] ();
[Link]("Name: " + name);
[Link]("Age: " + age);
[Link]("Height: " + height);
}
}