Computer Science, asked by arshahmadkhan6dec200, 16 days ago

W.A.P. to accept a number. If the number is even, calculate & print its square, print its cube. java using scanner class

Answers

Answered by Shivu516
0

Hope it helps ^_^

This program is in Java

import java.util.Scanner;

public class Even_Number_Only{

   public static void main(String [] args){

       Scanner sc = new Scanner(System.in);

       System.out.println("This program calculates the Square and Cube of the entered number if it's an even number");

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

       double num = sc.nextDouble();

       if (num % 2 == 0){

           double sq = Math.pow(num, 2);

           double cb = Math.pow(num, 3);

           System.out.println("Square of " + num + " = " + sq);

           System.out.println("Cube of " + num + " = " + cb);

       }

       else {

           System.out.println(num + " is not an even number");

       }

   }

}

These are all the possible outputs for the added conditions, the underlined values are the inputs

Output:

(i)

This program calculates the Square and Cube of the entered number if it's an even number

Enter a number: 6

Square of 6.0 = 36.0

Cube of 6.0 = 216.0

(ii)

This program calculates the Square and Cube of the entered number if it's an even number

Enter a number: 13

13.0 is not an even number

Hope you liked my answer ˶ᵔ ᵕ ᵔ˶

Attachments:
Similar questions