Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class LargestInArray {
- public static void main(String[] args) {
- final int LENGTH = 100;
- int[] values = new int[LENGTH];
- int currentSize = 0;
- System.out.println("enter valuess");
- Scanner in = new Scanner(System.in);
- while (in.hasNextDouble() && currentSize < values.length) {
- values[currentSize] = in.nextInt();
- currentSize++;
- }
- in.close();
- // finding the largest and smallest values
- int largest = values[0];
- int smallest = values[0];
- for (int i = 1; i < currentSize; i++) {
- if (values[i] > largest) {
- largest = values[i];
- }
- if (values[i] < smallest) {
- smallest = values[i];
- }
- }
- //printing stuff
- for (int i = 0; i < currentSize; i++) {
- System.out.print(values[i]);
- if (values[i] == largest && smallest != largest) {
- System.out.print(" is the largest value");
- }
- else if (values[i] == smallest && smallest != largest)
- {
- System.out.print(" is the smallest value");
- }
- else
- {
- System.out.print(" is the smallest and largest value");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement