Computer Science, asked by jeetagarwal972, 2 months ago

WAJP to check whether the number is an Amstrong number or not
(A number is said to tbe an amstrong if the sum of the cubes of the digitsis equal to the original
number)
Eg:153
OUTPUT:
Enter a number
It is an amstrong number
(b) Write a program to take n number of input from the user and check that the number is
positive or negative. Also terminate the program when 0 is entered.​

Answers

Answered by anindyaadhikari13
1

Answer:

The given programs are written in Java.

1. WAJP to check whether a number is an armstrong number or not.

import java.util.*;

public class ArmStrong  {

   public static void main(String args[])  {

       Scanner sc=new Scanner(System.in);

       System.out.print("Enter a number: ");

       int a=sc.nextInt(),b=0,c,d;

       c=a;

       while(c!=0) {

           d=c%10;

           b+=d*d*d;

           c/=10;

       }

       if(a==b)

           System.out.println("Armstrong number.");

       else

           System.out.println("Not an armstrong number.");

       sc.close();

   }

}

2. WAJP to name n number of inputs and check that the number is positive or negative.

import java.util.*;

public class Inputs {

   public static void main(String args[])  {

       Scanner sc=new Scanner(System.in);

       while (true)    {

           System.out.print("Enter a number:");

           int a=sc.nextInt();

           if(a>0)

               System.out.println("Number is positive.");

           else if(a<0)

             System.out.println("Number is negative.");

           else

               break;

       }

   }

}

Refer to the attachment for output.

•••♪

Attachments:
Similar questions