Positive and negative Learn programming Java

Lesson:

Flow Control


Exercise:

Positive and negative 10


Objetive:

Write a java program to get a number and answer whether it is positive or negative.


Code:

import java.util.*;
public class Main
{
	public static void main()
	{
		int a;
		System.out.print("Enter a number: ");
		a = Integer.parseInt(new Scanner(System.in).nextLine());
		if (a > 0)
		{
			System.out.println("is positive");
		}

		if (a < 0)
		{
			System.out.println("is negative");
		}
	}
}