top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Write a java program to check if a given number is positive, negative or zero?

+2 votes
670 views
Write a java program to check if a given number is positive, negative or zero?
posted Apr 10, 2017 by Atindra Kumar Nath

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Try something like this -

int number = input.nextInt();

if( number == 0)
{ System.out.println("Number is equal to zero"); }
else if (number > 0)
{ System.out.println("Number is positive"); }
else 
{ System.out.println("Number is negative"); }
answer Apr 10, 2017 by Salil Agrawal
Similar Questions
–1 vote

Write a C program to check if the given string is repeated substring or not.
ex
1: abcabcabc - yes (as abc is repeated.)
2: abcdabababababab - no

+2 votes

Rohit wants to add the last digits of two given numbers.
For example, If the given numbers are 267 and 154, the output should be 11.

Below is the explanation -
Last digit of the 267 is 7
Last digit of the 154 is 4
Sum of 7 and 4 = 11

Write a program to help Rohit achieve this for any given two numbers.

Note: The sign of the input numbers should be ignored. i.e.
if the input numbers are 267 and 154, the sum of last two digits should be 11
if the input numbers are 267 and -154, the sum of last two digits should be 11
if the input numbers are -267 and 154, the sum of last two digits should be 11
if the input numbers are -267 and -154, the sum of last two digits should be 11

...