Sunday, June 28, 2015

Armstrong Checker in Java

A simple program that I wrote using Java programming language that will check if the number given by the user is an armstrong number or not. The code is very simple but it uses already the concepts of object oriented programming.

I hope you will find my work  useful in a sense the logic of programming is also applied in this simple program.

If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Sample Program Output

Program Listing

import java.util.Scanner;


class armstrong_checker {
    public int check_armstrong_number(int value)
    {
       int temp = value;
int sum = 0;
int mod = 0;
while(temp != 0) {
mod = temp % 10;
sum = sum + (mod * mod * mod);
temp = temp / 10;
}
if(sum == value) 
System.out.println("The given number " + value + " is  Armstrong Number.");
else
System.out.println("The given number " + value + " is Not an Armstrong Number.");
    return 0;
    }


public static void main(String args[]) {
  Scanner scan = new Scanner(System.in);
   char a;
do
    {
  // creating of an object
  
  armstrong_checker number = new armstrong_checker();
      
  System.out.println();
  System.out.println("===== ARMSTRONG NUMBER CHECKER =====");
  System.out.println();
  System.out.print("Enter a Number :  ");
  int number_given =   scan.nextInt();
  
  System.out.println();
  number.check_armstrong_number(number_given);
  System.out.println("\n\n");
  System.out.print("Do you Want To Continue (Y/N) :=> ");
   a=scan.next().charAt(0);

   } while(a=='Y'|| a=='y');
          System.out.println("\n");
          System.out.println("\t ===== END OF PROGRAM ======");
         System.out.println("\n");
 }
  
   } // End of Program


















No comments:

Post a Comment