Upload files to "OOP/Java/Lab/Week3"
This commit is contained in:
parent
d7432df050
commit
490ff117eb
3 changed files with 74 additions and 27 deletions
|
@ -1,4 +1,5 @@
|
|||
import java.util.Scanner;
|
||||
import java.lang.Math;
|
||||
|
||||
class Armstrong{
|
||||
public static void main(String args[]){
|
||||
|
@ -6,15 +7,23 @@ class Armstrong{
|
|||
|
||||
int a,b,digit;
|
||||
int digisum=0;
|
||||
int c=0;
|
||||
|
||||
System.out.println("Enter the number you went to check for Armstrong-ness:");
|
||||
a = sc.nextInt();
|
||||
|
||||
b = a;
|
||||
|
||||
while(b!=0){
|
||||
c++;
|
||||
b/=10;
|
||||
}
|
||||
|
||||
b = a;
|
||||
|
||||
while(b!=0){
|
||||
digit = b%10;
|
||||
digisum += (digit*digit*digit);
|
||||
digisum += Math.pow(digit, c);
|
||||
b /= 10;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue