java_program 2

Practical Name: Write a java program to cheek whether given number is Armstrong or not  (use static keyword)

_______________________________________________________________

Program :

import java.util.Scanner;

class nu{

static void armstrong(){

int number ;

int check, rem, sum = 0;

System.out.println("Enter the number to be verified:");

Scanner sc = new Scanner(System.in);

number = sc.nextInt();

check = number;

while(check != 0) {

rem = check % 10;

sum = sum + (rem * rem * rem);

check = check / 10;

}

if(sum == number)

System.out.println("Given number "+number+" is an armstrong number. ");

else

System.out.println("Given number is not an armstrong number.");

}

}

public class ArmstrongNumber {

public static void main(String args[]) {

nu.armstrong();

}

}

 

 

OUTPUT:-




Post a Comment

Previous Post Next Post