BetinaUKTC

zadachiProg

Jun 7th, 2021
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1.  
  2. ////////////////////////////ПЪРВА///////////////////////////
  3. package Prog.Homework02;
  4.  
  5. import java.util.Arrays;
  6. import java.util.Collections;
  7. import java.util.LinkedHashSet;
  8. import java.util.Scanner;
  9.  
  10. public class Zadacha1 {
  11.  
  12. public static void main(String[] args) {
  13. Scanner scan = new Scanner(System.in);
  14. String[] arr = scan.nextLine().split(" ");
  15. int n = scan.nextInt();
  16.  
  17. for (int i = 0; i <= n; i++) {
  18. String command = scan.nextLine();
  19. //Reverse
  20. if (command.equalsIgnoreCase("reverse")) {
  21. Collections.reverse(Arrays.asList(arr));
  22. }
  23.  
  24. //Distinct
  25. if (command.equalsIgnoreCase("distinct")) {
  26. LinkedHashSet<String> set = new LinkedHashSet<>(Arrays.asList(arr));
  27. arr = set.toArray(new String[]{});
  28. }
  29.  
  30. //Replace
  31. if (command.contains("Replace")) {
  32. arr[Integer.parseInt(String.valueOf(command.charAt(8)))] = command.substring(10);
  33. }
  34. }
  35.  
  36. System.out.println(Arrays.toString(arr));
  37. }
  38. }
  39. ////////////////////////////////////////////Втора//////////////////////////////////////////
  40. package Prog.Homework02;
  41.  
  42. import java.util.HashMap;
  43. import java.util.Scanner;
  44.  
  45. public class Zadacha2 {
  46. public static void main(String[] args) {
  47. char[] arr = "abcdefghijklmnopqrstuvwxyz".toCharArray();
  48. Scanner scan = new Scanner(System.in);
  49. String input = scan.nextLine();
  50. HashMap<Character, Integer> map = new HashMap();
  51.  
  52. for (int i = 0; i < arr.length; i++) {
  53. map.put(arr[i], i);
  54. }
  55.  
  56. for (int i = 0; i < input.length(); i++) {
  57. System.out.println(input.charAt(i) + " -> " + map.get(input.charAt(i)));
  58. }
  59. }
  60. }
  61. /////////////////////////////////ТРЕТА/////////////////////////////////////////
  62. package Prog.Homework02;
  63.  
  64. import java.util.Scanner;
  65.  
  66. public class Zadacha3 {
  67. public static void main(String[] args) {
  68.  
  69. Scanner scan = new Scanner(System.in);
  70. String[] input = scan.nextLine().split(" ");
  71.  
  72. int min = Integer.MAX_VALUE;
  73. int max = Integer.MIN_VALUE;
  74. double sum =0;
  75. double avg = 0;
  76.  
  77.  
  78.  
  79. for (int i = 0; i < input.length; i++) {
  80. int curSum = Integer.parseInt(input[i]);
  81. sum+=curSum;
  82. if (curSum > max){
  83. max = curSum;
  84. }
  85. if(curSum<min){
  86. min = curSum;
  87. }
  88.  
  89. }
  90. avg = sum/input.length;
  91. System.out.println("Min = " + min);
  92. System.out.println("Max = " + max);
  93. System.out.println("Sum = " + sum);
  94. System.out.printf("Average = %.2f",avg);
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment