Vous êtes sur la page 1sur 3

Java Subtract two Matrices

Java Transpose Matrix


Java Multiply two Matrices
Java Three Dimension Array Program
Java Print String
Java Find Length of String
Java Compare two String
Java Copy String
Java Concatenate String
Java Reverse String
Java Delete Vowels from String
Java Delete Words from Sentence
Java Count Character in String
Java Count Word in Sentence
Java Remove Spaces from String
Java Sort a String
Java Uppercase to Lowercase
Java Lowercase to Uppercase
Java Swap two Strings
Java Check Anagram or Not
Java Generate Random Numbers
Java Read File
Java Write to File
Java Read & Display File Content
Java Copy File
Java Merge two File
Java List files in Directory
Java Delete File
Java Print Time & Date
Java Get IP Address
Java Shutdown Computer
Java Programming Tutorial
Java Tutorial
Java Interview Questions
Java Interview Questions
Java Programming Test
Java Programming Test
Give Online Test
Register Now
Login Page
All Test List

Java Program to Count Positive, Zero and Negative Numbers


« Previous Program Next Program »

Count Positive, Negative and Zero

To count the number of positive number, negative number, and zero from the given set of numbers
entered by the user, you have to first ask to the user to enter a set of numbers (10 numbers here) to
check all the number using for loop to count how many positive, negative, and zero present in the
provided set of numbers and display the output on the screen as shown in the following program.

Java Programming Code to Count Positive, Zero and Negative

Following Java Program ask the user to enter 10 number to check for the occurrence of positive
number, negative number and zero, then display the result on the screen:

/* Java Program Example - Count Positive, Negative, Zero */

import java.util.Scanner;

public class JavaProgram


{
public static void main(String args[])
{
int countp=0, countn=0, countz=0, i;
int arr[] = new int[10];
Scanner scan = new Scanner(System.in);

System.out.print("Enter 10 Numbers : ");


for(i=0; i<10; i++)
{
arr[i] = scan.nextInt();
}
for(i=0; i<10; i++)
{
{
if(arr[i] < 0)
{
countn++;
}
else if(arr[i] == 0)
{
countz++;
}
else
{
countp++;
}
}

System.out.print(countp + " Positive Numbers");


System.out.print("\n" + countn + " Negative Numbers");
System.out.print("\n" + countz + " Zero");
}
}

When the above Java Program is compile and executed, it will produce the following output:

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:

C Count Positive Negative Zero


C++ Count Positive Negative Zero

Java Online Test

Vous aimerez peut-être aussi