Advertisement
UniQuet0p1

Untitled

Sep 12th, 2021
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Answer {
  4.  
  5. public static void main (String[] param) {
  6.  
  7. // TODO!!! Solutions to small problems
  8. // that do not need an independent method!
  9.  
  10. // conversion double -> String
  11.  
  12. // conversion String -> int
  13.  
  14. // "hh:mm:ss"
  15.  
  16. // cos 45 deg
  17.  
  18. // table of square roots
  19.  
  20. String firstString = "ABcd12";
  21. String result = reverseCase (firstString);
  22. System.out.println ("\"" + firstString + "\" -> \"" + result + "\"");
  23.  
  24. // reverse string
  25.  
  26. String s = "How many words here";
  27. int nw = countWords (s);
  28. System.out.println (s + "\t" + String.valueOf (nw));
  29.  
  30. // pause. COMMENT IT OUT BEFORE JUNIT-TESTING!
  31.  
  32. final int LSIZE = 100;
  33. ArrayList<Integer> randList = new ArrayList<Integer> (LSIZE);
  34. Random generaator = new Random();
  35. for (int i=0; i<LSIZE; i++) {
  36. randList.add (Integer.valueOf (generaator.nextInt(1000)));
  37. }
  38.  
  39. // minimal element
  40.  
  41. // HashMap tasks:
  42. // create
  43. // print all keys
  44. // remove a key
  45. // print all pairs
  46.  
  47. System.out.println ("Before reverse: " + randList);
  48. reverseList (randList);
  49. System.out.println ("After reverse: " + randList);
  50.  
  51. System.out.println ("Maximum: " + maximum (randList));
  52. }
  53.  
  54. /** Finding the maximal element.
  55. * @param a Collection of Comparable elements
  56. * @return maximal element.
  57. * @throws NoSuchElementException if <code> a </code> is empty.
  58. */
  59. static public <T extends Object & Comparable<? super T>>
  60. T maximum (Collection<? extends T> a)
  61. throws NoSuchElementException {
  62. return Collections.max(a);
  63. }
  64.  
  65. /** Counting the number of words. Any number of any kind of
  66. * whitespace symbols between words is allowed.
  67. * @param text text
  68. * @return number of words in the text
  69. */
  70. public static int countWords (String text) {
  71. return 0; // TODO!!! Your code here
  72. }
  73.  
  74. /** Case-reverse. Upper -> lower AND lower -> upper.
  75. * @param s string
  76. * @return processed string
  77. */
  78. public static String reverseCase (String s) {
  79. return null; // TODO!!! Your code here
  80. }
  81.  
  82. /** List reverse. Do not create a new list.
  83. * @param list list to reverse
  84. */
  85. public static <T extends Object> void reverseList (List<T> list)
  86. throws UnsupportedOperationException {
  87. // TODO!!! Your code here
  88. }
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement