{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Assignment2

# Assignment2 - newInt = keyboard.nextInt if(newInt> max...

This preview shows page 1. Sign up to view the full content.

// Assignment #: 2 // Name: Michael Brown // StudentID: 1200601055 // Lecture: MWF 12:55pm-1:45pm // Description: This class reads an integer from a keyboard and prints it out // along with other messages. / import java.util.Scanner; // use the Scanner class located in the "java.util" directory public class Assignment2 { public static void main (String[] args) { int newInt = 0; int max = 0; int sumPos = 0; int sumOdd = 0; int totalEven = 0; Scanner keyboard = new Scanner(System.in); do {
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: newInt = keyboard.nextInt(); if(newInt > max) max = newInt; if(newInt > 0) sumPos += newInt; if(newInt % 2 != 0) sumOdd += newInt; if(newInt % 2 == 0) totalEven += 1; } while(newInt != 0); System.out.println("The maximum integer is " + max); System.out.println("The sum of the positive integers is " + sumPos); System.out.println("The sum of the odd integers is " + sumOdd); System.out.println("The count of even integers in the sequence is " + totalEven); } }...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern