Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Q11-Given an integer N, your task is to print all the Armstrong numbers which are present between 1 to N.
- Ans-import java.io.*; // for handling input/output
- import java.util.*; // contains Collections framework
- // don't change the name of this class
- // you can add inner classes if needed
- class Main {
- public static void main (String[] args) {
- // Your code here
- Scanner sc=new Scanner(System.in);
- int N=sc.nextInt();
- for(int i=1;i<=N;i++)
- { int sum=0;
- int temp=i;
- while(temp!=0)
- {
- sum=sum+(int)Math.pow(temp%10,3);
- temp=temp/10;
- }
- if(sum==i)
- {
- System.out.print(i+" ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement