1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| /*Write a program to find whether given no. is Armstrong or not.
Example :
Input - 153
Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */
class Armstrong{
public static void main(String args[]){
int num = Integer.parseInt(args[0]);
int n = num; //use to check at last time
int check=0,remainder;
while(num > 0){
remainder = num % 10;
check = check + (int)Math.pow(remainder,3);
num = num / 10;
}
if(check == n)
System.out.println(n+" is an Armstrong Number");
else
System.out.println(n+" is not a Armstrong Number");
}
} |
/*Write a program to find whether given no. is Armstrong or not.
Example :
Input - 153
Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */
class Armstrong{
public static void main(String args[]){
int num = Integer.parseInt(args[0]);
int n = num; //use to check at last time
int check=0,remainder;
while(num > 0){
remainder = num % 10;
check = check + (int)Math.pow(remainder,3);
num = num / 10;
}
if(check == n)
System.out.println(n+" is an Armstrong Number");
else
System.out.println(n+" is not a Armstrong Number");
}
}
Java program to find whether given no. is Armstrong or not using (if-else statement
)
Can I get the same program without using any functions?
I need simple program without using any function as I am learning java now.
you’re right java programs can easily be printed using if else
you’re right java programs can easily be printed using if else the coding is at website http://www.fuckjava.com
you are stupid to search on this worst wrong site
This link can help you …
See this link it would be helpful ..
http://www.techycage.com/2014/12/program-to-chech-wheather-number-is.html
class armstrong
{public static void accept(int no)
{int p=no,rem,s=0;
do
{rem=p%10;
s=s*10+rem;
p=p/10;
}
while(p!=0);
if(s==no)
System.out.println(“it is an armstrong”);
else
System.out.println(“it is not an armstrong”);
}}
what is the error in it could anyone please reply
public class Ams {
public static void accept(int no){
int p=no,rem,s=0;
do
{
rem=p%10;
s=s*10+rem;
p=p/10;
}
while(p!=0);
if(s==no)
System.out.println(“it is an ams”);
else
System.out.println(“not ams”);
}
}
}
http://javainterviewcracker.blogspot.in/
simple version of checking Armstrong here http://www.javaengineeringprograms.com/program-to-check-armstrong-number-in-java/
Another way to check if a number is an Armstrong number by taking user input…
package com.practice.java;
import java.util.Scanner;
class Armstrong{
public static void main(String args[]){
System.out.println(“Enter a number”);
Scanner sc = new Scanner(System.in);
String a = sc.nextLine();
int size = a.length();
System.out.println(“Length of the input number is = ” + size);
int num = Integer.parseInt(a);
int n = num;
int check=0,remainder;
while(num > 0){
remainder = num % 10;
check = check + (int)Math.pow(remainder,size);
num = num / 10;
}
if(check == n)
System.out.println(n+” is an Armstrong Number”);
else
System.out.println(n+” is not an Armstrong Number”);
sc.close();
}
}