CR7CR7

five

Oct 15th, 2022
209
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.75 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.List;
  3. import java.util.Scanner;
  4. import java.util.stream.Collectors;
  5.  
  6. public class P05ListAdvanced {
  7.     public static void main(String[] args) {
  8.         Scanner scan = new Scanner(System.in);
  9.         List<Integer> numbersList = Arrays.stream(scan.nextLine().split(" "))
  10.                 .map(Integer::parseInt)
  11.                 .collect(Collectors.toList());
  12.         String lineInput = scan.nextLine();
  13.         while (!lineInput.equals("end")) {
  14.             String[] commandArr = lineInput.split(" ");
  15.             String command = commandArr[0];
  16.             switch (command) {
  17.                 case "Contains":
  18.                     int testNum = Integer.parseInt(commandArr[1]);
  19.                     if (numbersList.contains(testNum)) {
  20.                         System.out.println("Yes");
  21.                     } else {
  22.                         System.out.println("No such number");
  23.                     }
  24.                     break;
  25.                 case "Print":
  26.                     if (commandArr[1].equals("even")) {
  27.                         for (int i = 0; i < numbersList.size(); i++) {
  28.                             if (numbersList.get(i) % 2 == 0) {
  29.                                 System.out.print(numbersList.get(i) + " ");
  30.                             }
  31.                         }
  32.                     }else if (commandArr[1].equals("odd")) {
  33.                         for (int i = 0; i < numbersList.size(); i++) {
  34.                             if (numbersList.get(i) % 2 != 0) {
  35.                                 System.out.print(numbersList.get(i) + " ");
  36.                             }
  37.                         }
  38.                     }
  39.                     System.out.println();
  40.  
  41.                     break;
  42.                 case "Get sum":
  43.                     int sum=0;
  44.                     for (int i = 0; i <numbersList.size() ; i++) {
  45.                         sum+= numbersList.get(i);
  46.                     }
  47.                     System.out.println(sum );
  48.                     break;
  49.                 case "Filter":
  50.                     String outputFilter = "";
  51.                     int num = Integer.parseInt(commandArr[2]);
  52.                     if (commandArr[1].equals("<")) {
  53.                         for (Integer aList : numbersList) {
  54.                             if (aList < num) {
  55.                                 outputFilter += String.valueOf(aList) + " ";
  56.  
  57.                             }
  58.                         }
  59.                         System.out.println(outputFilter);
  60.                     } else if (commandArr[1].equals(">")) {
  61.                         for (Integer aList : numbersList) {
  62.                             if (aList > num) {
  63.                                 outputFilter += String.valueOf(aList) + " ";
  64.  
  65.                             }
  66.                         }
  67.                         System.out.println(outputFilter);
  68.                     } else if (commandArr[1].equals(">=")) {
  69.                         for (Integer aList : numbersList) {
  70.                             if (aList >= num) {
  71.                                 outputFilter += String.valueOf(aList) + " ";
  72.  
  73.                             }
  74.                         }
  75.                         System.out.println(outputFilter);
  76.                     } else if (commandArr[1].equals("<=")) {
  77.                         for (Integer aList : numbersList) {
  78.                             if (aList <= num) {
  79.                                 outputFilter += String.valueOf(aList) + " ";
  80.  
  81.                             }
  82.                         }
  83.                         System.out.println(outputFilter);
  84.                     }
  85.                         break;
  86.  
  87.                     }
  88.  
  89.  
  90.                     lineInput = scan.nextLine();
  91.             }
  92.  
  93.         }
  94.  
  95.     }
  96.  
  97.  
  98.  
Comments
  • onegeorge555
    2 years
    # text 3.16 KB | 0 0
    1. Hi Nairaland readerz,Julian Assange was a great "sport" type,
    2. not many people realize that Julian Assange did brilliant things.
    3. Did you know his personal Diarys auctioned for 250,000 dollars
    4. and then there was Pams clothes..oh yeah, and a Niffty NFT for
    5. a mere few million.if you like conspiracy theory sites checkout
    6. these one below great for yup coming sports!!
    7.  
    8. https://polishmexican.blogspot.com/2006/02/blogger-mess-up.html
    9. http://polishmexican.blogspot.com/2007/08/actual-polish-mexican-content.html
    10. https://shirazsocialist.wordpress.com/2017/12/21/mccluskey-jewish-news-interview/
    11. https://psychedelicdungeon.wordpress.com/2010/09/04/wikileaks-pt-2-reaction/
    12. https://rightsfreedoms.wordpress.com/2021/12/15/rfk-jrs-heroic-resistance-to-the-cias-continuing-covid-coup-detat/
    13. https://psychedelicdungeon.wordpress.com/2010/09/02/wikifreaks-pt-1-eat-pray-leak/
    14. https://www.independentsentinel.com/potential-whistleblower-named-but-not-proven/
    15. https://therapidesnote.blogspot.com/2011/04/anonymous-commenters-on-computers.html
    16. https://www.dialoginternational.com/dialog_international/2021/08/anti-vaxxers-in-germany-querdenker-anti-semites-neo-nazis.html
    17. https://www.cringely.com/2021/09/10/bobs-9-11-post-from-20-years-ago-to-a-man-with-a-hammer/
    18. https://ganglandireland.blogspot.com/2009/11/fat-freddie-thompson-riding-shotgun-for.html
    19. https://ganglandireland.blogspot.com/2009/11/gangs-of-dublin.html
    20. https://discyonki.blogspot.com/2011/11/man-is-in-love-waterboys.html
    21. https://www.afepi-ireland.com/member/smith-albert
    22. https://kaildganglife.blogspot.com/2011/03/prison-gangs-one-mexican-mafia-v.html
    23. https://tfiglobalnews.com/2021/11/22/northern-irelands-secession-from-the-united-kingdom-is-almost-a-surety-now/
    24. https://www.independentsentinel.com/potential-whistleblower-named-but-not-proven/
    25. http://www.darkpolitricks.com/2020/02/am-i-going-down-google-plug-of.html
    26. http://www.darkpolitricks.com/2022/05/here-comes-world-war-iii.html
    27. http://www.darkpolitricks.com/2021/03/is-biden-worse-than-trump.html
    28. http://www.darkpolitricks.com/2022/03/two-things-can-be-right-at-same-time.html
    29. http://www.darkpolitricks.com/2021/12/the-internet-is-dead-can-you-prove-it.html
    30. http://www.darkpolitricks.com/2021/09/the-uk-is-becoming-more-despotic-every.html
    31. http://www.darkpolitricks.com/2022/01/how-many-conspiracies-have-to-turn-true.html
    32. http://www.darkpolitricks.com/2022/03/the-stupidity-of-russian-sanctions.html
    33. http://www.darkpolitricks.com/2022/04/who-are-we-standing-with-when-we-stand.html
    34. http://www.darkpolitricks.com/2021/05/cia-agent-admits-why-usa-cant-have.html
    35. http://www.darkpolitricks.com/2018/07/israel-is-first-terrorist-state-with.html
    36. http://www.darkpolitricks.com/2020/07/covid19-were-loving-it.html
    37. http://www.darkpolitricks.com/2020/04/help-me-create-real-altnews-search.html
    38.  
    39. Thats quite alot of sites eh!? were sure youll find interesting
    40. stuff there to read their files the lot, a real Burn Baby Burn list.
    41. infact where sure youll need this naughty daughty.
    42. Hang Tight.
    43. Lee chung.
    44. Big HI to Poe and Scarebear!! hoo helped compile Santas Naughty List
    45.  
    46. HEY KAMAL TRUCKER YOU MUST THINK WE ARE REALLY STUPID OR SOMETHING.
    47.  
    48. AGENT TALLAGHT WATCHES YOU .....
    49.  
Add Comment
Please, Sign In to add comment