1. Write a program in java to find square and cube of a positive number
If the number is positive, it executes and displays the result. But if a
negative number, the program must terminate its execution.
Answers
Answered by
1
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number to find the square and cube of it: ");
long num = sc.nextLong();
long num2 = num*num;
long num3 = num*num*num;
System.out.println("Square of "+num+" is: "+num2);
System.out.println("Cube of "+num+" is: "+num3);
}
}
Similar questions