Skip to content
ExamSpine

Lesson 2.3 · Write it

Sign check

A whole programPython or Java6 tests, 3 of them hidden

On a phone? Put the lines in order instead

Write a program that reads a whole number and prints its sign.

  1. If the number is greater than 0, print the number followed by is positive.
  2. If the number is less than 0, print the number followed by is negative.
  3. If the number is exactly 0, print the number followed by is zero.
  4. Print exactly one of those three lines. Spaces at the end are ignored.

Your program is run several times. Only what it prints is checked.

In Python, use int to convert. In Java, use Integer.parseInt.

Running Java here comes later. You can put this answer's lines in order instead. You can still write your Java answer (it stays while this page is open) and compare it with our worked solution. Or try this exercise in Python.

Examples

Your program is run 6 times: the 3 examples below, and 3 hidden ones that check the rules above. Only what it prints is checked.

  • a positive number (rule 1)

    You type

    1. typed: 5

    It prints

    5 is positive
  • a negative number (rule 2)

    You type

    1. typed: -3

    It prints

    -3 is negative
  • zero (rule 3)

    You type

    1. typed: 0

    It prints

    0 is zero
solution.pySolution.java