Respuesta :
Answer:
The program to this question as follows:
Program:
import java.util.*; //import package for user input
public class Number //defining class Number
{
public static void main(String[] ak)throws Exception //defining main method
{
int a1,b1,c1; //defining integer variable
int p_Count=0,n_Count=0,n_Zero=0,even_Count=0,odd_Count=0;
Scanner obx=new Scanner(System.in); //creating Scanner class object
System.out.println("Input all three numbers: "); //print message
//input from user
a1=obx.nextInt(); //input value
b1=obx.nextInt(); //input value
c1=obx.nextInt(); //input value
//check condition for a1 variable value
if(a1>0) //positive number
p_Count++;
else if(a1==0) //value equal to 0
n_Zero++;
else //value not equal to 0
n_Count++;
if(a1%2==0)//check even number
even_Count++;
else //for odd number
odd_Count++;
//check condition for b1 variable value
if(b1>0) //positive number
p_Count++;
else if(b1==0) //value equal to 0
n_Zero++;
else //value not equal to 0
n_Count++;
if(b1%2==0) //check even number
even_Count++;
else //for odd number
odd_Count++;
//check condition for c1 variable value
if(c1>0) //positive number
p_Count++;
else if(c1==0) //value equal to 0
n_Zero++;
else //value not equal to 0
n_Count++;
if(c1%2==0) //check even number
even_Count++;
else //for odd number
odd_Count++;
//print values.
System.out.println("positive number: "+p_Count);//message
System.out.println("negative number: "+n_Count); //message
System.out.println("zero number: "+n_Zero); //message
System.out.println("even number: "+even_Count); //message
System.out.println("odd number: "+odd_Count); //message
}
}
Output:
Input all three numbers:
11
22
33
positive number: 3
negative number: 0
zero number: 0
even number: 1
odd number: 2
Explanation:
In the above java program code a class is defined in this class three integer variable "a1,b1, and c1" is defined which is used to take input value from the user end, and other integer variable "p_Count=0, n_Count=0, n_Zero=0, even_Count=0, and odd_Count=0" is defined that calculates 'positive, negative, zero, even, and odd' number.
- In the next step, the conditional statement is used, in if block a1 variable, b1 variable, c1 variable calculates it checks value is greater then 0, it will increment the value of positive number value by 1.
- else if it will value is equal to 0. if this condition is true it will negative number value by 1
- else it will increment zero number values by 1.
- In this code, another if block is used, that checks even number condition if the value matches it will increment the value of even number by 1, and at the last print, method is used that print all variable values.