5.16 Armstrong Number in Java

Поделиться
HTML-код
  • Опубликовано: 16 янв 2016
  • An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 153 is an Armstrong number since 1^3 + 5^3 + 3^3 = 1+ 125+ 27 = 153.
    Check out our website: www.telusko.com
    Follow Telusko on Twitter: / navinreddy20
    Follow on Facebook:
    Telusko : / teluskolearnings
    Navin Reddy : / navintelusko
    Follow Navin Reddy on Instagram: / navinreddy20
    Subscribe to our other channel:
    Navin Reddy : / @navinreddy
    Telusko Hindi :
    / @teluskohindi
    Subscribe to the channel and learn Programming in easy way.
    Java Tutorial for Beginners: goo.gl/p10QfB
    C Tutorial Playlist : goo.gl/8v92pu
    Android Tutorial for Beginners Playlist : goo.gl/MzlIUJ
    XML Tutorial : goo.gl/Eo79do
    Design Patterns in Java : goo.gl/Kd2MWE
    Socket Programming in Java : goo.gl/jlMEbg
    Spring MVC Tutorial : goo.gl/9ubbG2
    OpenShift Tutorial for Beginners : goo.gl/s58BQH
    Spring Framework with Maven : goo.gl/MaEluO
    Sql Tutorial for Beginners : goo.gl/x3PrTg
    String Handling in Java : goo.gl/zUdPwa
    Array in Java : goo.gl/uXTaUy
    Java Servlet : goo.gl/R5nHp8
    Exception Handling in Java : goo.gl/N4NbAW

Комментарии • 111

  • @deepapn5049
    @deepapn5049 6 лет назад +17

    Thank you very much sir tomorrow is my java exam i didnt understood the concept which my tchr taught me but you made me understtand it thank u very much god bless u

  • @naveentandon993
    @naveentandon993 4 года назад +27

    Thnku so much Sir for clearing the concept..... may God bless u always ❤❤🙏🙏

  • @nicholasungar6676
    @nicholasungar6676 3 года назад +32

    For those who noticed that this formula only works with three digit numbers...
    public boolean isArmstrongNumber(int input) {

    if (input == (input % 10)) return true;

    int temp1 = input;
    int temp2 = input;
    int num,sum = 0;

    int digits = 0;

    while (temp2 > 0 ) {
    digits++;
    temp2 /= 10;
    }

    while (temp1 > 0) {
    num = temp1 % 10;
    temp1 /= 10;
    sum += Math.pow(num, digits);
    }

    if (input == sum) return true;
    else return false;
    }

    • @Enfieldic
      @Enfieldic Год назад +5

      Armstrong number is not what all are thinking
      Armstrong number mean
      Take an example
      12
      How many digits it is having 2
      So now we have to solve it like this 1²+2² but it is not equal to twelve so it's not an Armstrong number
      Take another example
      153
      How many digits is is having 3 so we have to add the cube of each of its digit because the number of digits are 3
      So the conclusion is that first check how many digits the number is having and then we have to send it to the power of each of its digit and make the sum of that number and check it whether it is equal to that number

    • @ASHOKkumar-pj3oj
      @ASHOKkumar-pj3oj Год назад

      Bro just give r*r*r*r instead r*r*r simple

    • @shristiprakashlifestudy5304
      @shristiprakashlifestudy5304 Год назад +5

      @@ASHOKkumar-pj3oj I am sorry but I don't agree,we have to use a formula valid for every number

  • @Dinesh_kuku
    @Dinesh_kuku 2 года назад +1

    Superbly explained!

  • @digjeetkaur9519
    @digjeetkaur9519 7 лет назад +8

    your explaination is superb , can u please also explain loops more how they work again and again

  • @dragonbooster5618
    @dragonbooster5618 4 года назад

    Nice explanation sir.Thank you so much

  • @Free_Bird78
    @Free_Bird78 4 года назад +14

    This is not a right method because it only implies when a number is of 3 digit only like 153, 370, 371 but if the number is of 4 digit like 1634(which is an armstrong number), it will show ,number is not an armstrong number' because it cubes the digit rather than multiplying it 4 times. Basically, there is another logic or program which implies in every digit number.

  • @fatemehrahmani6740
    @fatemehrahmani6740 4 года назад +1

    Thank u very much for your tutorial.

  • @maksimvolkov8892
    @maksimvolkov8892 4 года назад +2

    Nice, thank you for this video

  • @PraveenKumar-uj2ih
    @PraveenKumar-uj2ih 2 года назад

    Clear Explanation ......Thanks Bro

  • @NaveenKumar-be8xl
    @NaveenKumar-be8xl 2 года назад +1

    Simply super sir🙏

  • @NirajPRoxx
    @NirajPRoxx 6 лет назад +3

    Thank you :)

  • @ashutoshrai2717
    @ashutoshrai2717 Год назад +3

    Yes this is right program for only 3 digit number not for 4 digits

    • @mr.adityasingh9012
      @mr.adityasingh9012 5 месяцев назад

      Where -> sum = sum + r*r*r*r this will work on four digit....if you want check 5digit then....sum = sum+r*r*r*r*r

  • @sumeetsajjan
    @sumeetsajjan Год назад

    Thank u sir now easy to understand

  • @yasseralkindi7350
    @yasseralkindi7350 2 года назад

    brilliant, if you can add some explanation of the math logic. code wise, obviously its perfect!

  • @ozlemcetin5868
    @ozlemcetin5868 3 месяца назад

    I wish the calculation (r*r*r) could be dynamic because the number of multiplications is determined by the digit count. For instance, when determining if 1345 is an Armstrong number, as it has four digits, it should be r*r*r*r.

  • @shampachakraborty2515
    @shampachakraborty2515 6 лет назад +1

    Thanks

  • @shuvshaw9594
    @shuvshaw9594 4 года назад

    very helpful

  • @argonxgaming2045
    @argonxgaming2045 3 года назад

    Thankyou sir:)

  • @abdulravoof6444
    @abdulravoof6444 5 лет назад

    thanks bro

  • @mayankmittal9269
    @mayankmittal9269 3 года назад

    Thank you

  • @sanketkeluskar5583
    @sanketkeluskar5583 2 года назад

    really good
    :)

  • @shubhammhatre5089
    @shubhammhatre5089 Год назад

    but what if the number is 4 digit then we will have to use num raise to 4, so how will we change the r*r*r*r that time @telusko

  • @aadilhussain4556
    @aadilhussain4556 2 года назад

    Sir it is applicable only for 3 digit numbers if we have no like 8208, then we have write the condition like this sum=sum+ rev*rev*rev*rev; but sir is it not good practies

  • @mr_mouli_10
    @mr_mouli_10 5 месяцев назад

    chala thanks andi meku

  • @drake71000
    @drake71000 7 лет назад +6

    Armstrong number can be of more than 3 digits.

    • @Aulin001
      @Aulin001 4 года назад +1

      Yes

    • @rejaulmallik9397
      @rejaulmallik9397 3 года назад +1

      Yaah of course lol🤣🤣🤣😃😂😂you don't know this

  • @Anilkumar-ec8sj
    @Anilkumar-ec8sj 8 лет назад +3

    /* code */
    public class Armstrong {
    public static void main(String args[]){
    int n =370 , r,sum=0;
    int temp = n ;
    while(n>0){
    r=n%10;
    n=n/10;
    sum = sum+r*r*r;
    }
    if(temp==sum){
    System.out.println("Armstrong number");
    }
    else
    {
    System.out.println("Not Armstrong Number");
    }
    }

    }

  • @SA-ie6lr
    @SA-ie6lr 4 года назад +4

    What if we need to check a 4 digit number is armstrong or not?

    • @vinaygoraigorai8553
      @vinaygoraigorai8553 3 года назад +2

      import java .util .*;
      public class Main {
      public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      System.out.print("input no.");
      int n = sc.nextInt();
      int value = n;
      int r = 0, sum = 0, c = 0;
      for (int i = n; i > 0; i /= 10) {
      c++;
      }
      while (n > 0) {
      r = n % 10;
      sum += (Math.pow(r, c));
      n = n / 10;
      }
      if (sum == value)
      System.out.print("armstrong no.");
      else
      System.out.print("not");
      }
      }

    • @mallikarjunareddy6122
      @mallikarjunareddy6122 2 года назад +1

      public class Armstrong {
      public static void main(String args[])
      {
      int n= 153;
      int temp=n;
      int sum=0;
      while(n>0)
      {
      int r=n%10;
      n=n/10;
      sum = sum+r*r*r;//Note :-if n=a number of digits then that maney r's has to multipliy.
      }
      //Note:for ex:n=153,n has a 3 digits 1,5 and 3...so r*r*r.,n=1634,n has a 4 digits 1,6,3 and 4...so r*r*r.
      if(temp==sum)
      System.out.println(temp+ " is a armstrong");
      else
      {
      System.out.println(temp+ " is not an armstrong");
      }

      }
      }

  • @skasif4476
    @skasif4476 3 года назад +1

    This program is valid for 3 digit numbers only...can you generalize for all the numbers we wish to check??

    • @aviroxi
      @aviroxi 2 года назад

      this code is take input from the user and find whether given number is armstrong or not
      import java.util.*;
      //armstrong number or not?
      public class armstrongnumber{
      public static void main(String[] args){
      Scanner sc= new Scanner(System.in);
      int x=sc.nextInt();
      int t=x,s=x;
      int n=0,sum=0,ind=0;
      while(x>0){
      ++n;
      x=x/10;
      }
      while(t>0){
      ind=t%10;
      sum=sum+power(ind,n);
      t=t/10;
      }
      if(s==sum)
      System.out.print("true");
      else
      System.out.print("false");
      }
      static int power(int N, int P)
      {
      if (P == 0)
      return 1;
      else
      return N * power(N, P - 1);
      }
      }

  • @tanveerjafri3052
    @tanveerjafri3052 4 года назад +4

    int num;
    Scanner scanner = new Scanner(System.in);
    System.out.println("Enter the number for ArmStrong Number");
    num = scanner.nextInt();
    int temp = num;
    int save = 0;
    int sum = 0;
    save = num%10;
    sum = (num/10)%10;
    num = (num/10)/10;
    num = num*num*num + sum*sum*sum + save*save*save;
    if (temp == num)
    System.out.println("This is ArmStrong Number: " + num);
    else
    System.out.println("This is not a ArmStrong Number");

  • @sivapradeep977
    @sivapradeep977 3 года назад +4

    int n=153;
    str N1=n;
    int length =len(N1);
    int ANS,FIN_ANS=0;
    for(i=0;i

  • @algorithmgaming7416
    @algorithmgaming7416 5 лет назад

    Why did we use while loop

  • @sumitchaturvedi5933
    @sumitchaturvedi5933 6 лет назад +1

    thank u sir

  • @ujjwalgoyal7215
    @ujjwalgoyal7215 3 года назад +1

    Hello sir ,
    This program is not working for 4 digit numbers.

    • @aviroxi
      @aviroxi 2 года назад +1

      this code is take input from the user and find whether given number is armstrong or not
      import java.util.*;
      //armstrong number or not?
      public class armstrongnumber{
      public static void main(String[] args){
      Scanner sc= new Scanner(System.in);
      int x=sc.nextInt();
      int t=x,s=x;
      int n=0,sum=0,ind=0;
      while(x>0){
      ++n;
      x=x/10;
      }
      while(t>0){
      ind=t%10;
      sum=sum+power(ind,n);
      t=t/10;
      }
      if(s==sum)
      System.out.print("true");
      else
      System.out.print("false");
      }
      static int power(int N, int P)
      {
      if (P == 0)
      return 1;
      else
      return N * power(N, P - 1);
      }
      }

  • @perpetual23
    @perpetual23 7 лет назад +1

    it's nt working fr the input 1 to 9.. shows nt armstrng..

    • @SmartProgramming
      @SmartProgramming 6 лет назад +4

      import java.util.Scanner;
      class ArmstrongNumber
      {
      public static void main(String args[])
      {
      Scanner s=new Scanner(System.in);
      System.out.println("Enter The Number : ");
      int no=s.nextInt();
      int t1=no;
      int leng=0;
      while(t1 != 0)
      {
      leng=leng+1;
      t1=t1/10;
      }
      int t2=no;
      int arm=0;
      int rem;
      while(t2 != 0)
      {
      int mul=1;
      rem=t2%10;
      for(int i=1;i

  • @mohammadadil456
    @mohammadadil456 3 месяца назад

    I am new to java I was tasked to write a program to find Armstrong number my code:
    int a=125;
    do {System.out.println((a%10)*(a%10)*(a%10));
    a=a/10;

    } while(a!=0);
    Output:
    125
    8
    1
    can someone explain my mistake.

  • @Naidu-wv1dy
    @Naidu-wv1dy 7 месяцев назад

    explaination is good but this code will works three digit number only

  • @murliengineering6130
    @murliengineering6130 Год назад

    Is we take a 9474 it's not working because that power is 9^4+4^4+7^4+4^4=9474

  • @mangeshshelke1846
    @mangeshshelke1846 2 года назад

    If user enter number 4 digits then?..
    It's just hard coded value

  • @pasupuletikoteswararao9184
    @pasupuletikoteswararao9184 3 года назад +1

    It is for only 3 digits
    What if we have n number

    • @aviroxi
      @aviroxi 2 года назад

      this code is take input from the user and find whether given number is armstrong or not
      import java.util.*;
      //armstrong number or not?
      public class armstrongnumber{
      public static void main(String[] args){
      Scanner sc= new Scanner(System.in);
      int x=sc.nextInt();
      int t=x,s=x;
      int n=0,sum=0,ind=0;
      while(x>0){
      ++n;
      x=x/10;
      }
      while(t>0){
      ind=t%10;
      sum=sum+power(ind,n);
      t=t/10;
      }
      if(s==sum)
      System.out.print("true");
      else
      System.out.print("false");
      }
      static int power(int N, int P)
      {
      if (P == 0)
      return 1;
      else
      return N * power(N, P - 1);
      }
      }

  • @karan_yt_family
    @karan_yt_family 3 года назад

    Ossam

  • @sekharraj525
    @sekharraj525 Год назад

    How to work on scanner class

  • @karnataka8863
    @karnataka8863 Год назад

    Used r x r x r for 3digit no if user use any no then how we come to know the power ?

    • @ts9dream
      @ts9dream Год назад +2

      We use another loop to get the size of number and then we use math.pow(digit,size)

    • @InInferno
      @InInferno Год назад

      @@ts9dream thank you

  • @balapramothc.m.
    @balapramothc.m. 2 года назад +1

    why only cube

  • @venkateswarluguntaka7370
    @venkateswarluguntaka7370 4 года назад

  • @simplecoding5435
    @simplecoding5435 10 месяцев назад

    this method is wrong armstrong number is not like that suppose if we have 4 digit no then what to do

  • @murliengineering6130
    @murliengineering6130 Год назад

    Sir this program is not work for 4 digit

  • @shuvshaw9594
    @shuvshaw9594 4 года назад

    int x=153,j=x,r,sum=0;
    while(x>0)
    {
    r=x%10;
    sum=sum+(r*r*r);
    x=x/10;
    }
    if(sum==j)
    System.out.println("y");
    else
    System.out.println("n");

  • @koushikaisrat3670
    @koushikaisrat3670 8 лет назад +4

    what about if the number n has four or five digits ?

    • @karnveerayush
      @karnveerayush 8 лет назад

      +koushika israt It will make no difference.

    • @AbhiShek-nv3vq
      @AbhiShek-nv3vq 7 лет назад +7

      It'll definitely make a difference. We'll have to multiply the remainder the number of times there are digits in the number. e.g. 9474 is an armstrong number which is equal to: 9*9*9*9+ 4*4*4*4+ 7*7*7*7+ 4*4*4*4= 9474.

    • @drake71000
      @drake71000 7 лет назад +2

      Or even more than that. If we are not sure how many digits are there in a number than what to do?

    • @NirajPRoxx
      @NirajPRoxx 6 лет назад

      we have to multiply each digit only three times in order to get cube.

    • @SmartProgramming
      @SmartProgramming 6 лет назад +5

      import java.util.Scanner;
      class ArmstrongNumber
      {
      public static void main(String args[])
      {
      Scanner s=new Scanner(System.in);
      System.out.println("Enter The Number : ");
      int no=s.nextInt();
      int t1=no;
      int leng=0;
      while(t1 != 0)
      {
      leng=leng+1;
      t1=t1/10;
      }
      int t2=no;
      int arm=0;
      int rem;
      while(t2 != 0)
      {
      int mul=1;
      rem=t2%10;
      for(int i=1;i

  • @anushreebachhav9299
    @anushreebachhav9299 3 года назад

    why didnt we simply do, (n==sum) ?

    • @aviroxi
      @aviroxi 2 года назад

      to check if they are same, if yes then it is an armstrong number

    • @RohitRaj-bt7qx
      @RohitRaj-bt7qx 2 года назад

      If we check (n == sum) it won't work because..
      After completion of the while loop,
      As we wrote that n = n/10;
      The value will be 0.153 (in case of number 153)
      So.. We stored the given input in temp to check it at the end of the program.
      As if we wrote (n == sum)
      0.153 never matches to 153.

  • @DAME-RAJATHS
    @DAME-RAJATHS Год назад

    I wish you had done it n^n not n^3

  • @sekharraj525
    @sekharraj525 Год назад

    If you given numbers 4digit

  • @dhanalaskhmidhanu3468
    @dhanalaskhmidhanu3468 3 года назад +1

    I really not understand what you did ?????

  • @user-vx1bw8xc4e
    @user-vx1bw8xc4e 3 года назад

    Its is applicablr only for 3 digit number
    It is not useful
    How to calculate 4 /2/5 digit number are armstrong

    • @aviroxi
      @aviroxi 2 года назад

      this code is take input from the user and find whether given number is armstrong or not
      import java.util.*;
      //armstrong number or not?
      public class armstrongnumber{
      public static void main(String[] args){
      Scanner sc= new Scanner(System.in);
      int x=sc.nextInt();
      int t=x,s=x;
      int n=0,sum=0,ind=0;
      while(x>0){
      ++n;
      x=x/10;
      }
      while(t>0){
      ind=t%10;
      sum=sum+power(ind,n);
      t=t/10;
      }
      if(s==sum)
      System.out.print("true");
      else
      System.out.print("false");
      }
      static int power(int N, int P)
      {
      if (P == 0)
      return 1;
      else
      return N * power(N, P - 1);
      }
      }

  • @atulgupta3407
    @atulgupta3407 Месяц назад +1

    why you have so many browsers , i think you do sussy things

  • @elonmusk.0
    @elonmusk.0 2 года назад

    /* improvised status: below code works for a number with any number of digits user wishes(i.e. user input - any number of digits) */
    import java.lang.Math;
    import java.util.*;
    public class armstrong_num {
    public boolean check_armstrong(int n){
    int sum = 0,i=0,r,t,dgts,m; // variable 't' and 'dgts' are used to store original value of 'n' because we need to compare changed value with original value since later in loops 'n' value is changed.
    t = n;
    dgts = n;
    while (dgts!=0){ // This loop is to count the total digits in 'n'. e.g. n=123, so 'i' will be 3. We will use this 'i' to as the power of r. So with this we can find any armstrong number not just 3 digit number.
    dgts = dgts / 10;
    i++;
    }
    System.out.println("Total digits in numbers: "+i);
    while (n>0){
    r = n % 10; //seperate last digit and stored in 'r'
    n = n / 10; //n will no longer have last digit (it will have digits other than last one)
    m = (int)Math.pow(r, i); // (r) ^ (i) // if n = 2345 then 'i' will be 4(from upper while loop)
    sum += m;
    //System.out.println(sum); // this shows 'r' with power of 'i' one by one.
    }
    if(t == sum){
    return true;
    }
    return false;
    }
    public static void main(String[] args) {
    armstrong_num an = new armstrong_num();
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter a number to check whether it is armstrong number or not");
    int n = sc.nextInt();
    //int n = 9474; //e.g. 9474 , 1634 are armstrong numbers
    boolean b = an.check_armstrong(n); //if function(check_armstrong) is static, we can call function directly i.e. no need for an object in main i.e. 'an'.
    if(b){//true
    System.out.println(n+" is a armstrong number.");
    }
    else{
    System.out.println(n+" is not a armstrong number");
    }
    }
    }

  • @jaishukla5054
    @jaishukla5054 5 лет назад +1

    8208 is Also an Armstrong number but it's doesn't work

  • @pranavgupta9132
    @pranavgupta9132 7 лет назад

    CAN YOU GIVE PROGRAM TO PRINT MAGIC NUMBERS FROM 1 TO 1000 ?

  • @ravinsr69
    @ravinsr69 5 лет назад

    It does not works for 4 digits or more

  • @abdulrahim7763
    @abdulrahim7763 5 месяцев назад

    tried without while loop..this is working fine for me (give any number within the limit of integer data type)
    Scanner sc=new Scanner(System.in);

    System.out.println("Enter any number to find out if it is a Armstrong number or not");

    int input=sc.nextInt();

    String s="";
    String count=s.valueOf(input);
    int input_size = count.length();
    int digit;
    double Armstrong=0;
    double result=0;
    int actual=input;

    if(input>0)
    {

    for(int i=1;i

  • @thegrimare2917
    @thegrimare2917 7 лет назад +6

    sorry dude it does not work

    • @SmartProgramming
      @SmartProgramming 6 лет назад +1

      import java.util.Scanner;
      class ArmstrongNumber
      {
      public static void main(String args[])
      {
      Scanner s=new Scanner(System.in);
      System.out.println("Enter The Number : ");
      int no=s.nextInt();
      int t1=no;
      int leng=0;
      while(t1 != 0)
      {
      leng=leng+1;
      t1=t1/10;
      }
      int t2=no;
      int arm=0;
      int rem;
      while(t2 != 0)
      {
      int mul=1;
      rem=t2%10;
      for(int i=1;i

  • @shivaprakashreddyyeredla1705
    @shivaprakashreddyyeredla1705 2 года назад +1

    I didn't understand this vedio 😭😭

  • @sudhakar3991
    @sudhakar3991 Год назад +2

    This logic is not working......dont refer this

    • @anusmitasen2009
      @anusmitasen2009 5 месяцев назад

      It's completely correct, check your program

  • @saikumarn3547
    @saikumarn3547 6 лет назад

    //To check whether given number is armstrong number or not
    import java.util.Scanner;
    class ArmstrongNumber
    {
    public static void main(String[] args)
    {
    Scanner scanner=null;
    int n=0,r=0,sum=0,temp=0;
    scanner=new Scanner(System.in);
    System.out.println("Enter number to check armstrong or not : ");
    n=scanner.nextInt();
    temp=n;
    int length=(int)Math.log10(temp)+1;
    while(n>0){
    r=n%10;
    n=n/10;
    sum=sum+((int)Math.pow(r,length));
    }
    if(temp==sum){
    System.out.println(temp+" is armstrong number");
    }
    else{
    System.out.println(temp+" is not a armstrong number");
    }
    }
    }

  • @Fbielijah
    @Fbielijah 6 лет назад

    Video is not good

  • @PramodKumar1207
    @PramodKumar1207 7 лет назад

    import java.util.Scanner;
    public class arm {
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.out.println("-- Armstrong number --");
    System.out.println("Enter the no");
    Scanner sc=new Scanner(System.in);
    int n = sc.nextInt();
    int original=n;
    int count=0;
    int arm=0;
    while(n>0)
    {
    n =n/10;
    count++;
    }
    System.out.println("Length of the number: "+count);
    n = original;
    while(n>0)
    { int rem = n%10;
    n=n/10;
    int temp=1;
    for(int i=count;i>0;i--)
    {
    temp=temp*rem;
    }
    arm=arm+temp;
    }
    if(arm == original)
    {
    System.out.println(original+ " is an Armstrong number");
    }
    else
    {
    System.out.println(original+ " is not an Armstrong number");
    }
    }
    }

  • @aviroxi
    @aviroxi 2 года назад

    this code is take input from the user and find whether given number is armstrong or not
    import java.util.*;
    //armstrong number or not?
    public class armstrongnumber{
    public static void main(String[] args){
    Scanner sc= new Scanner(System.in);
    int x=sc.nextInt();
    int t=x,s=x;
    int n=0,sum=0,ind=0;
    while(x>0){
    ++n;
    x=x/10;
    }
    while(t>0){
    ind=t%10;
    sum=sum+power(ind,n);
    t=t/10;
    }
    if(s==sum)
    System.out.print("true");
    else
    System.out.print("false");
    }
    static int power(int N, int P)
    {
    if (P == 0)
    return 1;
    else
    return N * power(N, P - 1);
    }
    }

  • @Sumit.Kr.singh93
    @Sumit.Kr.singh93 Год назад

    import java.util.*;
    public class Main {
    public static void main(String[] args) {
    // int n = 371;
    Scanner scn =new Scanner(System.in);
    int n=scn.nextInt();

    int nod = numOfDigits(n);
    int ans = 0;
    int backup = n;
    while (n > 0) {
    int digit = n % 10;
    ans = ans + (int)Math.pow(digit, nod);
    n = n / 10;
    }
    if (backup == ans) {
    System.out.println("true");
    } else {
    System.out.println("false");
    }
    }
    public static int numOfDigits(int n) {
    int ans = 0;
    while (n != 0) {
    n =n/ 10;
    ans++;
    }
    return ans;
    }
    }
    this will work ffor your every input.