Skip to content

Instantly share code, notes, and snippets.

@johnhmj
Created March 9, 2010 22:40
Show Gist options
  • Save johnhmj/327235 to your computer and use it in GitHub Desktop.
Save johnhmj/327235 to your computer and use it in GitHub Desktop.
import java.io.*;
import java.util.*;
public class Main {
// Start of main
public static void main(String[] args) {
PrintStream jout = new PrintStream(System.out);
Scanner jin = new Scanner(System.in);
int[] Counter = new int[2];
for(int i = 0; i < Counter.length; i ++)
{
Counter[i] = 0;
}
while( true )
{
jout.printf("Enter an integer: ");
String strN = jin.nextLine();
if( strN.compareTo("0") == 0 )
{
break;
}
if( strN.charAt(0) == '-' )
{
Counter[1] ++;
}
else
{
Counter[0] ++;
}
}
jout.printf("Positive = %d\n", Counter[0]);
jout.printf("Negative = %d\n", Counter[1]);
}// End of main
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment