Write a ‘java’ program to check whether given number is Armstrong or not.(Use static keyword)
{
public static void main(String[] args)
{
Scanner
scan = new Scanner(System.in);
System.out.print("Enter the Number: ");
num = scan.nextInt();
temp = num;
while(temp!=0)
{
rem = temp%10;
res = res + (rem*rem*rem);
temp = temp/10;
}
if(num==res)
System.out.println("\nArmstrong
Number.");
else
System.out.println("\nNot an
Armstrong Number.");
}
}
Define an abstract class Shape with
abstract methods area () and volume (). Derive abstract class Shape into two
classes Cone and Cylinder. Write a java Program to calculate area and volume of
Cone and Cylinder.(Use Super Keyword.)
import java.util.*;
abstract class Shape
{
abstract public void area();
abstract public void vol();
}
class Cone extends Shape
{
int r,s,h;
Cone(int r,int s,int h)
{
super();
this.r=r;
this.s=s;
this.h=h;
}
public void area()
{
}
public void vol()
{
System.out.println("volume
of Cone = "+(3.14*r*r*h)/3);
}
}
class Cylinder extends Shape
{
int r,h;
Cylinder(int r,int h)
{
this.r=r;
this.h=h;
}
public void area()
{ System.out.println("Area
of Cylinder = "+(2*3.14*r*h));
}
public void vol()
{
System.out.println("volume
of Cylinder = "+(3.14*r*r*h));
}
}
class Slip15
{
public static void main(String
a[])
{
Scanner sc = new
Scanner(System.in);
System.out.println("Enter
radius, side and height for cone");
int r =sc.nextInt();
int s1 =sc.nextInt();
int h =sc.nextInt();
Shape s;
s=new Cone(r,s1,h);
s.area();
s.vol();
System.out.println("Enter
radius, height for cylinder");
r =sc.nextInt();
h =sc.nextInt();
s=new Cylinder(r,h);
s.area();
s.vol();
}
}