lab_branch #1

Merged
aadit merged 3 commits from lab_branch into main 2024-08-31 01:22:44 +05:30
Showing only changes of commit f8aace509b - Show all commits

View File

@ -1,37 +1,26 @@
import java.util.Scanner; import java.util.Scanner;
import java.lang.Math;
class Armstrong {
class Armstrong{
public static void main(String args[]){ public static void main(String[] args) {
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
int a,b,digit; System.out.println("Enter a number");
int digisum=0;
int c=0; int n = sc.nextInt();
int b = String.valueOf(n).length();
System.out.println("Enter the number you went to check for Armstrong-ness:"); int sum = 0;
a = sc.nextInt(); int temp = n;
while (temp > 0) {
b = a; int r = temp % 10;
sum += Math.pow(r, b);
while(b!=0){ temp /= 10;
c++; }
b/=10; if (sum == n) {
} System.out.println("The given number is an Armstrong Number.");
} else {
b = a; System.out.println("The given number is not an Armstrong Number.");
}
while(b!=0){ sc.close();
digit = b%10; }
digisum += Math.pow(digit, c); }
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.");
}
}
}