Computer Science, asked by Toushif4623, 11 months ago

Program to accept an int type value as a parameter and print the square of it if it is more than 120 otherwise print its cube


LuckyYadav2578: in which language?

Answers

Answered by rakeshchennupati143
13

Program in Java:

import java.util.*;

public class Main{

     public class void main(String args[]){

           Scanner sc = new Scanner(System.in);

           System.out.println("Enter a int value : ");

           int num = sc.nextInt();

           if(num>120){

                 System.out.println("square of "+num+" is "+(num*num));

           }else{

                 System.out.println("cube of "+num+" is "+(num*num*num));

           }

     }

}

Output-1:

Enter a int value : 120

square of 120 is 14400

Output-2:

Enter a int value : 121

cube of 121 is 1771561

Explanation:

  • i took number from the user using Scanner() class and stored it in num variable of int type
  • and checked if the number is greater than 120 or not if true i printed the square by multiplying the number itself in print() statement
  • if not then i calculated the cube of the number by multiplying the number with itself 3 times

----Hope you understood my program,if you liked it mark as brainliest,it would really help me.   :)

Answered by swaibsneha21
2

Answer:

Here is your answer friends :-

Explanation:

PROGRAM INPUT :-

import java.util.*;

public class Main{

    public class void main(String args[]){

          Scanner sc = new Scanner(System.in);

          System.out.println("Enter a int value : ");

          int num = sc.nextInt();

          if(num>120){

                System.out.println("square of "+num+" is "+(num*num));

          }else{

                System.out.println("cube of "+num+" is "+(num*num*num));

          }

    }

}

Hope it help to u

Similar questions