Computer Science, asked by rakshirott, 1 year ago

Given number is even OR odd if it is even print square of that number or if it is odd print cube of that number.

can anyone write program for this and help me

Answers

Answered by harindersaini2pcf8vf
12

Hey there !

The answer for your question for JAVA (with scanner class) is as follows :-

import java.util.* ;

class abc

{

  void main()

   {

      int n;

     Scanner sc = new Scanner(System.in);

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

     n = sc.nextInt();

     if (n%2 ==0)

     System.out.println("The number is even. Its square is " + (n*n));

     else

     System.out.println("The number is odd. Its cube is " + (n*n*n));

  }

}



Hope it helps :-)












harindersaini2pcf8vf: Please mark as brainliest if it really helped...please...please
harindersaini2pcf8vf: If you need the program without scanner class then please tell, I'll write it.
harindersaini2pcf8vf: If you also need the variable description then also tell, I'll write that also.
Similar questions