Advertisement
micher43

E6.2 part A

Oct 23rd, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class E62 {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner s = new Scanner(System.in);
  8.         System.out.println("enter your number of inputs");
  9.         int numberOfInputs = s.nextInt();
  10.         int largestValue = 0;
  11.         int smallestValue = 0;
  12.        
  13.        
  14.         System.out.println("enter input value");
  15.         int inputValue = s.nextInt();
  16.         largestValue = inputValue;
  17.         smallestValue = inputValue;
  18.        
  19.        
  20.         for(int i = 1; i < numberOfInputs; i++){
  21.             System.out.println("enter input value");
  22.             inputValue = s.nextInt();
  23.             if(inputValue > largestValue){
  24.                 largestValue = inputValue;
  25.             }
  26.             else if(inputValue < smallestValue){
  27.                 smallestValue = inputValue;
  28.             }
  29.         }
  30.         System.out.println(largestValue + " is the largest value");
  31.         System.out.println(smallestValue + " is the smallest value");
  32.  
  33.     }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement