This website includes Education Information like a programming language, job interview question, general knowledge.mathematics

Education log

PageNavi Results No.

Ads

Saturday, August 26, 2023

java program to find armstrong number using scanner class

 java program to find armstrong number using scanner class


In this Tutorial Today Learn java Example. follow java program to find armstrong number using scanner class

example.


Armstrong number in Java. Here we have written the code in four different ways standard, using for loop, recursion, while loop and also with different examples as like: between 100 and 999, between 1 to 1000 and between 1 to 500 with sample outputs and online execution tool embedded.


Example Java armstrong number

import java.util.Scanner;

class ArmstrongWhile

{

public static void main(String[] arg)

{

int i=100,arm;

System.out.println("Armstrong numbers between 100 to 999");

while(i<1000)

{

arm=armstrongOrNot(i);

if(arm==i)

System.out.println(i);

i++;

}

}

static int armstrongOrNot(int num)

{

int x,a=0;

while(num!=0)

{

x=num%10;

a=a+(x*x*x);

num/=10 ;

}

return a;

}

}



No comments:

Post a Comment