Tsuki11

Untitled

Jun 19th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. public class Tuple <T1, T2>{
  2. private T1 item1;
  3. private T2 item2;
  4.  
  5. public Tuple(T1 item1, T2 item2){
  6. this.item1 = item1;
  7. this.item2 = item2;
  8. }
  9.  
  10. public T1 getItem1() {
  11. return item1;
  12. }
  13.  
  14. public T2 getItem2() {
  15. return item2;
  16. }
  17. }
  18.  
  19. import java.io.BufferedReader;
  20. import java.io.IOException;
  21. import java.io.InputStreamReader;
  22.  
  23. public class Main {
  24. public static void main(String[] args) throws IOException {
  25. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  26.  
  27.  
  28. int inputLine = 3;
  29. String line;
  30. while (inputLine-- > 0) {
  31. String[] tokens = reader.readLine().split("\\s+");
  32.  
  33. switch (inputLine) {
  34. case 2: {
  35. String name = tokens[0] + " " + tokens[1];
  36. Tuple<String, String> tuple = new Tuple<>(name, tokens[2]);
  37. System.out.println(tuple.getItem1() + " -> " + tuple.getItem2());
  38. break;
  39. }
  40. case 1:
  41. Tuple<String, Integer> tuple = new Tuple<>(tokens[0], Integer.parseInt(tokens[1]));
  42. System.out.println(tuple.getItem1() + " -> " + tuple.getItem2());
  43. break;
  44. default:
  45. Tuple<Integer, Double> tuple1 = new Tuple<>(Integer.parseInt(tokens[0]), Double.parseDouble(tokens[1]));
  46. System.out.println(tuple1.getItem1() + " -> " + tuple1.getItem2());
  47. break;
  48. }
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment