Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- String[] elements = input.split(" ");
- int[] nums = new int [elements.length];
- for (int i = 0; i < elements.length; i++) {
- nums[i] = Integer.parseInt(elements[i]);
- }
- // input ////////////
- int max = Integer.MIN_VALUE;
- int min = Integer.MAX_VALUE;
- long sum = 0;
- for (int i = 0; i < nums.length; i++) {
- int num = nums[i];
- if(num > max){
- max = num;
- }
- if(num < min){
- min = num;
- }
- sum += num;
- }
- double avg1 = (double)sum / nums.length;
- System.out.println(min);
- System.out.println(max);
- System.out.println(sum);
- System.out.println(avg1);
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- int[] numbers = new int[10];
- for (int i=0; i<numbers.length; i++) {
- numbers[i] = i+1;
- }
- numbers[3] = 20;
- numbers[5] = numbers[2] + numbers[7];
- for (int i = 0; i<numbers.length; i++) {
- System.out.printf("numbers[%d] = %d\n", i, numbers[i]);
- }
- for (int num : numbers) {
- System.out.println(num);
- }
- String[] names = { "Peter", "Maria", "Katya", "Todor" };
- for (int i = 0; i<names.length; i++) {
- System.out.printf("names[%d] = %s\n", i, names[i]);
- }
- for (String name : names) {
- System.out.println(name);
- }
- names[4] = "Nakov"; // ArrayIndexOutOfBoundsException
- //names.length = 5; // array.length is read-only field
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- //// sort LEYYERS
- // Read a number n and n text lines
- Scanner scanner = new Scanner(System.in);
- int n = scanner.nextInt();
- scanner.nextLine();
- String[] lines = new String[n];
- for (int i = 0; i < n; i++) {
- lines[i] = scanner.nextLine();
- }
- // Sort the array of strings
- Arrays.sort(lines);
- // Print the sorted array
- for (int i = 0; i < lines.length; i++) {
- System.out.println(lines[i]);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- // sort NUMBERS
- Scanner scanner = new Scanner(System.in);
- int n = scanner.nextInt();
- scanner.nextLine();
- String[] lines = input.split(" ");
- //String[] lines = new String[n];
- int[] numStr = new int [lines.length];
- for (int i = 0; i < n; i++) {
- lines[i] = scanner.nextLine();
- }
- for (int i = 0; i < lines.length; i++) {
- numStr[i] = Integer.parseInt(lines[i]);
- }
- // Sort the array of numbers
- Arrays.sort(numStr);
- // Print the sorted array
- for (int i = 0; i < numStr.length; i++) {
- System.out.println(numStr[i]);
- }
- //////////////////// 2 reshenie za sort a NUMBERS ////////////////////////////////////////////
- // Read a number n and n text lines
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- String[] lines = input.split(" ");
- int[] numStr = new int [lines.length];
- // for (int i = 0; i < n; i++) {
- // lines[i] = scanner.nextLine();
- // }
- for (int i = 0; i < lines.length; i++) {
- numStr[i] = Integer.parseInt(lines[i]);
- }
- // Sort the array of numbers
- Arrays.sort(numStr);
- // Print the sorted array
- for (int i = 0; i < numStr.length; i++) {
- System.out.println(numStr[i]);
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement