Assignment2 - newInt = keyboard.nextInt(); if(newInt >...

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

View Full Document Right Arrow Icon
// 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 {
Background image of page 1
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

This note was uploaded on 10/01/2010 for the course CSE 205 taught by Professor Takamura during the Spring '10 term at University of Arizona- Tucson.

Ask a homework question - tutors are online