Write an Algorithm to input a number. If number is a positive number then print the square of the number else add 2 to the number and print it.
Answers
Answered by
0
Explanation:
import java.util.*
public class Numbers
{
public static void main(String[]args)
{
Scanner sc=new Scanner;
{
System.out.println("Enter a no.");
double b=in.nextInt();
if(b=>0)
{
double d=b*b;
System.out.println("the square of positive no.="+d);
}
else
{
double f=b+2.0;
System.out.println("the negative no. with 2 added="+f);
}
}
}
}
Similar questions