Lab 1

//Kenny Cruz
//CET 3640
//Lab #1
import java.util.Scanner;
public class Lab1 {

public static void main(String[] args) {

int counter = 0;
int sum = 0;
int opt;
int num = 0;
float average;
int current;
int Largest = 0;
int secondLargest = 0;
int Smallest = 0;
int secondSmallest = 0;
int firstNumber = 0;
float count = 0;

Scanner input = new Scanner(System.in);

do
{
System.out.println(“MENU”);
System.out.println(“Select”);
System.out.println(” 1. Enter A Number”);
System.out.println(” 2. Exit”);

opt= input.nextInt();

if( opt == 1)
{
System.out.println(“Enter a value: “);
num = input.nextInt();

current = num;

if (counter==0)
{

firstNumber = current;
Largest = current;
secondLargest = current;
Smallest = current;
secondSmallest = current;
}

else if(counter == 1)

{
if (current < Largest)                         secondLargest = current;                     else if (current > Smallest)
secondSmallest = current;
}

if (current > Largest)
{
secondLargest=Largest;
Largest = current;
}

else if (current > secondLargest)
secondLargest = current;

if (current < Smallest)
{
secondSmallest = Smallest;
Smallest = current;
}
else if (current < secondLargest)
secondLargest = current;

sum=sum+num;

counter++;
count = counter;

}

else if (opt == 2)
opt = ‘n’;

else
System.out.println(“Try a different number\n: “);

}while ( opt != ‘n’);

average= sum/count;

System.out.println(“The first number is: ” + firstNumber);

System.out.println(“The ast number is: ” + num);

System.out.println(“Total numbers are: ” + counter);

System.out.println(“The minimum lalue is: ” + Smallest);
System.out.println(“The second minimum value is: ” + secondSmallest);

System.out.println(“The maximum value is: ” + Largest);
System.out.println(“The second maximum value is: ” + secondLargest);

System.out.println(“The sum of all the Integers is: ” + sum);

System.out.println(“The average is: ” + average);

}
}

Leave a Reply

Your email address will not be published. Required fields are marked *