Two negative numbers Learn programming Java

Lesson:

Flow Control


Exercise:

Two negative numbers 36


Objetive:

Create a java program to accept two numbers from the user and answer if both are negative or not.


Code:

import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
		int number1;
		int number2;

		System.out.print("number 1: ");
		number1 = Integer.parseInt(new Scanner(System.in).nextLine());

		System.out.print("number 2: ");
		number2 = Integer.parseInt(new Scanner(System.in).nextLine());

		if ((number1 < 0) && (number2 < 0))
		{
			System.out.println("the numbers are negative");
		}

		if (!((number1 < 0) && (number2 < 0)))
		{
			System.out.println("the numbers are NOT negative");
		}
	}
}