Saturday, September 30, 2017

if + else if + else


Challenge: Write a program that reads an integer and prints whether it is negative, zero, or positive

Solution:

import java.util.Scanner;

public class lab4_1
{
public static void main(String []args)
{
//double a=2,b=1;
Scanner in= new Scanner(System.in);   
//int x=0;//b=0;//b=1;
System.out.println("Please enter an integer number");

int x=in.nextInt();




if (x<0)
{
System.out.println("You have entered a negative number");
}
else if(x==0)
{
System.out.println("The number is enter is 0");
}
else 
{
System.out.println("You have entered a posite number");
}
 
}
}

No comments:

Post a Comment