Write a program in Java to enter a number. If the number is positive even display
three succeeding even numbers. If the number is negative odd, display
three preceding odd numbers. Otherwise, display the message “Number
is neither a positive even nor a negative odd.”
Answers
Answered by
1
Answer:
Java Program to check if Number is Positive or Negative
In this post, we will write two java programs, first java programs checks whether the specified number is positive or negative. The second program takes the input number (entered by user) and checks whether it is positive or negative and displays the result.
→ If a number is greater than zero then it is a positive number
→ If a number is less than zero then it is a negative number
→ If a number is equal to zero then it is neither negative nor positive.
noExample 1: Program to check whether the given number is positive or negative
In this program we have specified the value of number during declaration and the program checks whether the specified number is positive or negative. To understand this program you should have the basic knowledge of if-else-if statement in Core Java Programming.
Example 2: Check whether the input number(entered by user) is positive or negative
Here we are using Scanner to read the number entered by user and then the program checks and displays the result.
Try these related Programs
(1)=Java Program to Add two Numbers
(2)=Java Program to Multiply two Numbers
(3)=Java Program to read number from Standard input
Hope this answer helpful for you
Similar questions
English,
3 months ago
Sociology,
3 months ago
Math,
6 months ago
Science,
11 months ago
Social Sciences,
11 months ago