Upload files to "OOP/Java/Lab/Week3"
This commit is contained in:
parent
a48eede8ad
commit
ee1a31b5e1
5 changed files with 103 additions and 0 deletions
28
OOP/Java/Lab/Week3/Armstrong.java
Normal file
28
OOP/Java/Lab/Week3/Armstrong.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
class Armstrong{
|
||||
public static void main(String args[]){
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
int a,b,digit;
|
||||
int digisum=0;
|
||||
|
||||
System.out.println("Enter the number you went to check for Armstrong-ness:");
|
||||
a = sc.nextInt();
|
||||
|
||||
b = a;
|
||||
|
||||
while(b!=0){
|
||||
digit = b%10;
|
||||
digisum += (digit*digit*digit);
|
||||
b /= 10;
|
||||
}
|
||||
|
||||
if(digisum == a){
|
||||
System.out.println("The number is an armstrong number.");
|
||||
}else{
|
||||
System.out.println("The number is not an armstrong number.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue