SHARE
TWEET

Java loop/if basics

eimkasp May 23rd, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Main {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5.         int[] masyvas = {100, 200, -100, 0, 5, 10};
  6.         int min = Integer.MAX_VALUE; // 2147483647
  7.         int max = Integer.MIN_VALUE;
  8.         int minIndex;
  9.         int maxIndex;
  10.  
  11. //        System.out.println(Integer.MAX_VALUE);
  12.  
  13.         for(int i = 0; i < masyvas.length; i++) {
  14.             if(masyvas[i] < min) {
  15.                 min = masyvas[i];
  16.                 minIndex = i;
  17.             }
  18.  
  19.             if(masyvas[i] > max) {
  20.                 max = masyvas[i];
  21.                 maxIndex = i;
  22.             }
  23.  
  24.         }
  25.  
  26.         System.out.println("Didziausias skaicius: "  + max);
  27.         System.out.println("Maziausias skaicius: "  + min);
  28.  
  29.  
  30.     }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top