Input a number and display its square if it is less than 50 ,else display its cube.plz its urgent JAVA PROGRAM
Home
/
Computer Science
/
Input a number and display its square if it is less than 50 ,else display its cube.plz its urgent JAVA PROGRAM
Java is a machine independent language which can work on any platform. Its an object oriented programming which stress on object rather than data.
The main parts while doing Java programming are package, Class ,input variables, condition updating.
The following programming is done by io package of Java.
CODING :---
import Java. io. *;
class check
{
public static void main(String args[])throws Exception
{
DataInputStream in = new DataInputStream(System.in);
int n, i , s=0;
System. out. println("Enter any number ");
n=Interger.parseInt(in.readLine());
s=n*n;
if(n<=50)
System. out. println("The square of number is"+s);
else
System. out. println("The cube of number is"+(n*n*n));
}
}
OUTPUT :-
1)-n=5
s=5×5
=25
Since its less than 50
The square of number is 25.
2)-n=9
s=9*9=81
Since, the square is more than 50.
The cube of number is 729
Listen sq nd cube could be taken out by n*n and n*n*n respectively without using math function.