Write a programme to accept a number.Check its a 2 digit number or not if its a 2 digit number then display the sum of the digits.And then display the square of the sum.Otherwise display square of the number.
Answers
Answer:
import java.util.Scanner;
public class KboatSpecialNumber
{
public void checkNumber() {
Scanner in = new Scanner(System.in);
System.out.print("Enter a 2 digit number: ");
int orgNum = in.nextInt();
int num = orgNum;
int count = 0, digitSum = 0, digitProduct = 1;
while (num != 0) {
int digit = num % 10;
num /= 10;
digitSum += digit;
digitProduct *= digit;
count++;
}
Explanation:
Newton's laws of motion relate an object's motion to the forces acting on it. In the first law, an object will not change its motion unless a force acts on it. In the second law, the force on an object is equal to its mass times its acceleration.