Saturday, November 28, 2015

BlueJ Program On Weak Arm Number



What is Weak Arm number


Weak arm numbers are those where the number is equal to the sum of the digits to the power 'n'. 'n' is the number of digits in the number and it is maximum for the unit digit value and decreases by one

 For example to check whether 153 is an Weak Arm number, the sum would be like 1 1 + 5 2 + 3 3. 153 is not weak arm number. Examples of weak arm numbers are 89, 135, 175, 518, 598

Download eBook on BlueJ 

import java.io.*;
public class WA
{
void showWeakArm() throws Exception
{
 int c=0;
 int a,d,b,n;
 double sum=0;
BufferedReader br=new  BufferedReader(new InputStreamReader(System.in));
System.out.println("enter  the no.");
n=Integer.parseInt(br.readLine());
b=n;
while(b >0)
{
 c++;
 b=b/10;
}
b=n;
while(b >0)
{
a=b%10;
sum=sum+Math.pow(a,c);
b/=10;
c--;
}
if(n==(int)sum)
System.out.println(n+ " is A WeakArm Number");
else
System.out.println(n+ " is Not A WeakArm Number");
}
public static void main(String args[]) throws Exception
{
WA ob=new WA();
ob.showWeakArm();
}
}

Related PostBlueJ Programs on Number

9 comments:

  1. Using C :

    #include
    #include
    #include
    int main()
    {
    int n,i,count,r, a[100],s=0,temp,power;
    printf("Enter the number:");
    scanf("%d",&n);
    temp=n;
    count = log10(n)+1;
    power=count;
    for(i=0;i<count;i++)
    {
    r=n%10;
    a[i]=r;
    n=n/10;
    printf("\na[%d] = %d",i,a[i]);
    }
    for(i=0;i<count;i++)
    {
    s=s+round(pow(a[i],power));
    power--;
    }
    if(temp==s)
    printf("\nWeak Arm Number");
    else
    printf("\nNot Weak Arm Number");
    }

    ReplyDelete
  2. Very helpful and logically done๐Ÿ˜Š๐Ÿ˜Š

    ReplyDelete
  3. Your program is wrong because you have not inasilized the variable sum .So it's a wrong program first check and then write an program

    ReplyDelete
    Replies
    1. Not clear Dear, please check both (your comment and the program)

      Delete

Subscribe via email

Enter your email address:

Delivered by FeedBurner