Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do you write a program that will read 30 integers from the keyboard, then co

ID: 3624881 • Letter: H

Question

How do you write a program that will read 30 integers from the keyboard, then compute the number of positive evens (not including 0), negative evens, positive odds, negative odds, and zeros. Then print the results to the screen.

Explanation / Answer

import java.util.Scanner; public class Integers { public static void main(String args[]) { int posEvens = 0; int negEvens = 0; int posOdds = 0; int negOdds = 0; int zeroes = 0; int number; Scanner scan = new Scanner(System.in); for (int i = 0; i < 30; i++) { System.out.print("Enter integer number " + (i + 1) + ": "); number = scan.nextInt(); if (number % 2 == 0) { if (number > 0) { posEvens++; } if (number < 0) { negEvens++; } else zeroes++; } if (number % 2 == 1) { if (number > 0) { posOdds++; } if (number < 0) { negOdds++; } } } System.out.print("There were " + posEvens + " positive and " + negEvens + " negative EVENS. " + "There were " + posOdds + " positive and " + negOdds + " negative ODDS. There were " + zeroes + " ZEROes."); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote