1 / 2100%
import java.util.*; //importing the java utility
public class Lab4
{
public static void main (String[] args)
{
//set up scanner
Scanner scan = new Scanner (System.in);
//set up integers
int input,even,odd,max,min,smallint,largeint,count;
double average,sum,avgcount;
//initialize variables
count=0;
even=0;
odd=0;
sum=0;
min=0;
max=0;
avgcount=0;
//start program
System.out.println("Enter a series of values (0 to quit):"); //
input = scan.nextInt(); //accept first input
//evaluate first and subsequent inputs
if (input != 0) {
min = input;
max = input;
if (input % 2 == 0 ) {
even++;
}
else {
odd++;
}
sum = input + sum;
count++;
avgcount++;
//if criteria fits start loop
while(input != 0){
input = scan.nextInt(); //accept first input
//break the loop if the input equals zero
if (input != 0) {
if (max < input) {
max = input;
}
if (min > input) {
min = input;
}
if (input % 2 == 0 ) {
even++;
}
else {
/*-------------------------------------------------------------------------
// AUTHOR:
// FILENAME: Lab4.java
// SPECIFICATION:
// FOR: CSE 110- Lab #4
// TIME SPENT:
//-----------------------------------------------------------*/
odd++;
}
sum = input + sum;
count++;
avgcount++;
}
}
//declare results
System.out.println("The smallesat integer is "
+min);
System.out.println("The largest integer is "
+max);
System.out.println("The total number of intergers
entered is " +count);
System.out.println("Total even numbers entered is
" +even);
System.out.println("Total odd numbers entered is "
+odd);
average = (sum/avgcount);
System.out.println("The average value is "
+average);
}
//if first value was zero, state the following:
else {
System.out.println("No data was entered.");
}
}
}
Powered by TCPDF (www.tcpdf.org)
Students also viewed