Skip to content

Instantly share code, notes, and snippets.

@JorgeOlvera
Created November 6, 2013 14:58
Show Gist options
  • Save JorgeOlvera/7337408 to your computer and use it in GitHub Desktop.
Save JorgeOlvera/7337408 to your computer and use it in GitHub Desktop.
/*2. Write a program (save it as PosNeg) that prompts the user for an integer number and
it would display on screen the message “The number is positive” if it is a positive number
and “The number is negative” if otherwise.
*/
import java.util.Scanner;
import java.io.*;
public class PosNeg {
public static void main(String[] args) {
int danumber;
Scanner input = new Scanner(System.in);
System.out.println("Please input a number");
danumber = input.nextLine();
if (danumber > 0){
System.out.println("This number is positive");
}
else if (danumber < 0) {
System.out.println("This number is negative");
else (danumber = 0)
System.out.println ("Trick question...this number is neither negative nor positive. For practical purposes, consider it positive");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment