Java Program
// Use of if...else if...else statement
public class IfElseifElseStructure {
public static void main(String args[])
{
int a=10;
int b=10;
if (a<b) {
System.out.printf("%d is less than %d", a,b);
}else if(a>b) {
System.out.printf("%d is less than %d", b,a);
}else {
System.out.printf("%d is equal to %d", a,b);
}
}
}
import java.util.Scanner;
/* Write a program to check whether a given number is armstrong number
(an armstrong number is the number which is equal to the sum of cubes of individual digits)
*/
public class CheckArmstrong {
public static void main(String args[]){
int num,r,s,t;
s=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number: ");
num=sc.nextInt();
t=num;
while(num!=0){
r= num %10;
s=(int) (s+Math.pow(r,3));
num=num/10;
}
if(s==t) {
System.out.println("Armstrong Number");
}
else {
System.out.println("Not armstrong Number");
}
}
}
public class IfElseifElseStructure {
public static void main(String args[])
{
int a=10;
int b=10;
if (a<b) {
System.out.printf("%d is less than %d", a,b);
}else if(a>b) {
System.out.printf("%d is less than %d", b,a);
}else {
System.out.printf("%d is equal to %d", a,b);
}
}
}
import java.util.Scanner;
/* Write a program to check whether a given number is armstrong number
(an armstrong number is the number which is equal to the sum of cubes of individual digits)
*/
public class CheckArmstrong {
public static void main(String args[]){
int num,r,s,t;
s=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number: ");
num=sc.nextInt();
t=num;
while(num!=0){
r= num %10;
s=(int) (s+Math.pow(r,3));
num=num/10;
}
if(s==t) {
System.out.println("Armstrong Number");
}
else {
System.out.println("Not armstrong Number");
}
}
}
Comments