Advertisement
teddy-popova

Цикъл за намиране на максимално число + в масив

Nov 29th, 2020 (edited)
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. ///////С ЦИКЪЛ//////
  2. import java.util.Scanner;
  3. public class MAXnumber {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.         System.out.print("Брой числа:");
  8.         int n = scan.nextInt();
  9.        
  10.         System.out.println("Въведи числата:");
  11.         int max = 0;
  12.        
  13.         for (int i=1; i<=n; i++) {
  14.         int number = scan.nextInt();
  15.         if (number > max){
  16.          max = number;
  17.         }
  18.     }
  19.         System.out.println("Най-голямото е:" + max);
  20.  
  21.     }
  22.  
  23. }
  24.  
  25.  
  26. //////В МАСИВ////////
  27. public class masiv {
  28.    
  29. public static void main(String[]args) {
  30.     int[]arr = {28,3,7,20,90,99,78,65,4,10};   
  31.     int max = arr[0];
  32.     for(int i = 1; i<=arr.length-1; i++) {
  33.         if(max<arr[i]) {
  34.             max=arr[i];
  35.         }
  36.     }
  37.     System.out.println(max);
  38.  }
  39.  
  40. }
  41.  
  42.  
  43.  
  44. ////////////////////
  45. public class Masivi {
  46.  
  47.     public static void main(String[] args) {
  48.    
  49.         int[] arr = {11,5,4,8,2,9,3,7,24};
  50.         for (int i = 0; i < arr.length; i++) {
  51.  
  52.                for (int u = 0; u < arr.length-i; u++) {
  53.                       if (arr[i]>arr[i+u]) {
  54.                           int a = arr[i];
  55.                           arr[i] = arr[i+u];
  56.                           arr[i+u] = a;
  57.                       }
  58.                  }
  59.           }
  60.         System.out.print("{");
  61.         for (int j = 0; j < arr.length; j++) {
  62.                 System.out.print(" " + arr[j] + " ");
  63.         }
  64.         System.out.print("}");
  65.  
  66.        
  67.  
  68.     }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement