Computer Science, asked by vaibhavkhunger08, 11 months ago

Write a java program to take a value from the user and print the square of it unless it is less than 120. The message "I cannot square number" should appear if the user
assigns the number greater than 120. Using loop​

Answers

Answered by ƦαıηвσωUηıcσяη
40

public class AddTwoNumbers {

public static void main(String[] args) {

int num1 = 5, num2 = 15, sum;

sum = num1 + num2;

System.out.println("Sum of these numbers: "+sum);

}

}

Answered by Anonymous
36

Answer:

class PrimeCheck

{

public static void main(String args[] )

{

int temp;

boolean isPrime=true;

Scanner scan= new Scanner(System.in);

System.out.println("Enter any number:");

//capture the input in an integer

int num=scan.nextInt();

scan.close();

for(int i=2;i<=num/2;i++)

{

temp=num%i;

if(temp==0)

{

isPrime=false;

break;

}

}

//If isPrime is true then the number is prime else not

if(isPrime)

System.out.println(num + " is a Prime Number");

else

System.out.println(num + " is not a Prime Number");

}

}

Similar questions