Class 9
Java programming
Answer the following:-
1) Write a program to find out addition, subtraction, a multiplication
and division of two numbers. The numbers are 18 and 15.
Ans:-
class equation
{
public static void main()
{
int a=18, b=15;
int c=a + b;
int d=a - b;
int e=a * b;
int f=a / b;
System.out.println(“Addition =”+c) ;
System.out.println(“Subtract =”+d) ;
System.out.println(“Multiplication =”+e) ;
System.out.println(“Division =”+f) ;
}
}
2) Write a program to find out square and cube of a number. The
number is 25.
Ans:-
class squareCube
{
public static void main()
{
int a=25;
int c=a * a;
int d=a * a * a;
System.out.println(“Square =”+c) ;
System.out.println(“Cube =”+d) ;
}
}
3) Write a program to find out twice and thrice of a number. The
number is 7.
Ans:-
class equation
{
public static void main()
{
int a=7;
int c=a * 2;
int d=a * 3;
System.out.println(“Twice =”+c) ;
System.out.println(“Thrice =”+d) ;
}
}
4) Write a program to find out area and perimeter of rectangle and
square. Where l=18, b=15, s=5.
Ans:-
class equation
{
public static void main()
{
int l=18, b=15,s=5;
int c=2*(l + b);
int d=l * b;
int e=s * s;
int f=4 * s;
System.out.println(“Perimeter of rectangle=”+c) ;
System.out.println(“Area of rectangle=”+d) ;
System.out.println(“Area of square=”+e) ;
System.out.println(“Perimeter of square=”+f) ;
}
}
5) Write a program to find out area and circumference of circle.
When radius is 4cm.
class circle
{
public static void main ()
{
double a, c, r=4.0;
a=3.14*r*r;
c=2*3.14*r;
System.out.println(a);
System.out.println(c);
}
}
6) Print your name and roll number in different lines.
class biodata
{
public static void main ()
{
String n=”Ram”;
int r = 4;
System.out.println(n);
System.out.println(r);
}
}
7) Write a program to convert the kilometre into meter, Where the
kilometre is 5.
class distance
{
public static void main ()
{
Int km=5;
double m;
m=km*1000;
System.out.println(m+” km“);
}
}
8) WRP to find out Celsius where the Fahrenheit is 8.
class temperature
{
public static void main ()
{
double c;
int f=8;
c=((f-32) *5)/9;
System.out.println(c);
}
}
9) Write a program to find out the average of three numbers. The
numbers are 15, 16, 17.
class average
{
public static void main()
{
int a,b,c;
a=15; b=16; c=17;
double sum, avg;
sum = a + b + c;
avg = sum / 3;
System.out.println(“ Average = “+avg) ;
}
}
10 ) Write a program to multiply the three numbers. The numbers are
8,9,10;
class multiply
{
public static void main()
{
int a, b, c;
a=8; b=9; c=10;
int d = a * b * c;
System.out.println(“Multiplication = “ + d) ;
}
}