Scanner input = new Scanner(System.in);
int positiveCount = 0, negativeCount = 0;
for (int i = 1; i <= 5; i++) {
System.out.print("Enter number " + i + ": ");
int num = input.nextInt();
if (num > 0) {
positiveCount++;
} else if (num < 0) {
negativeCount++;
}
}
System.out.println("Positive: " + positiveCount);
System.out.println("Negative: " + negativeCount);
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter