From 04e118a64952696d377f685f9ba2e76900326b73 Mon Sep 17 00:00:00 2001 From: Ayushitgithub <101935175+Ayushitgithub@users.noreply.github.com> Date: Tue, 18 Oct 2022 22:38:51 +0530 Subject: [PATCH] armstrong.java --- armstrong.java | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 armstrong.java diff --git a/armstrong.java b/armstrong.java new file mode 100644 index 0000000..9045bec --- /dev/null +++ b/armstrong.java @@ -0,0 +1,51 @@ +import java.util.Scanner; +import java.lang.Math; +public class Main +{ +//function to check if the number is Armstrong or not +static boolean Arms(int n) +{ +int p, git=0, last=0, s=0; + +p=n; + +while(p>0) +{ +p = p/10; +git++; +} +p = n; +while(p>0) +{ + +last = p % 10; + +s += (Math.pow(last, git)); +//removes the last digit +p = p/10; +} + +if(n==s) + +return true; + +else return false; +} + +public static void main(String args[]) +{ +int number; +Scanner sc= new Scanner(System.in); +System.out.print("Enter the number: "); + +number=sc.nextInt(); +if(Arms(number)) +{ +System.out.print(" It is an Armstrong No "); +} +else +{ +System.out.print(" It is Not Armstrong "); +} +} +}