Sunday, 21 January 2018

Armstrong Number

package com.tutorial4u;

import java.util.Scanner;

public class Armstrong {
       public static void main(String[] args) {
             int remsum=0,temp;
             System.out.print("Enter a number to check Armstrong : ");
             Scanner sc = new Scanner(System.in);
             int num = sc.nextInt();
             temp = num;
             while(num!=0){
                    rem = num % 10;
                    sum = sum+rem*rem*rem;
                    num = num/10;
             }
             if(temp == sum){
                    System.out.println("Given number is Armstrong");
             }else{
                    System.out.println("Given number is Armstrong");
             }
       }

}


Output:

Enter a number to check Armstrong : 153


Given number is Armstrong

No comments:

Post a Comment

No of Occurrence in Array

package com.tutorial4u; import java.util.HashMap; /************************************************************  No of Occurrence in Array...