Created
November 6, 2013 14:58
-
-
Save JorgeOlvera/7337408 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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