Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class P05ListAdvanced {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- List<Integer> numbersList = Arrays.stream(scan.nextLine().split(" "))
- .map(Integer::parseInt)
- .collect(Collectors.toList());
- String lineInput = scan.nextLine();
- while (!lineInput.equals("end")) {
- String[] commandArr = lineInput.split(" ");
- String command = commandArr[0];
- switch (command) {
- case "Contains":
- int testNum = Integer.parseInt(commandArr[1]);
- if (numbersList.contains(testNum)) {
- System.out.println("Yes");
- } else {
- System.out.println("No such number");
- }
- break;
- case "Print":
- if (commandArr[1].equals("even")) {
- for (int i = 0; i < numbersList.size(); i++) {
- if (numbersList.get(i) % 2 == 0) {
- System.out.print(numbersList.get(i) + " ");
- }
- }
- }else if (commandArr[1].equals("odd")) {
- for (int i = 0; i < numbersList.size(); i++) {
- if (numbersList.get(i) % 2 != 0) {
- System.out.print(numbersList.get(i) + " ");
- }
- }
- }
- System.out.println();
- break;
- case "Get sum":
- int sum=0;
- for (int i = 0; i <numbersList.size() ; i++) {
- sum+= numbersList.get(i);
- }
- System.out.println(sum );
- break;
- case "Filter":
- String outputFilter = "";
- int num = Integer.parseInt(commandArr[2]);
- if (commandArr[1].equals("<")) {
- for (Integer aList : numbersList) {
- if (aList < num) {
- outputFilter += String.valueOf(aList) + " ";
- }
- }
- System.out.println(outputFilter);
- } else if (commandArr[1].equals(">")) {
- for (Integer aList : numbersList) {
- if (aList > num) {
- outputFilter += String.valueOf(aList) + " ";
- }
- }
- System.out.println(outputFilter);
- } else if (commandArr[1].equals(">=")) {
- for (Integer aList : numbersList) {
- if (aList >= num) {
- outputFilter += String.valueOf(aList) + " ";
- }
- }
- System.out.println(outputFilter);
- } else if (commandArr[1].equals("<=")) {
- for (Integer aList : numbersList) {
- if (aList <= num) {
- outputFilter += String.valueOf(aList) + " ";
- }
- }
- System.out.println(outputFilter);
- }
- break;
- }
- lineInput = scan.nextLine();
- }
- }
- }
Comments
-
- Hi Nairaland readerz,Julian Assange was a great "sport" type,
- not many people realize that Julian Assange did brilliant things.
- Did you know his personal Diarys auctioned for 250,000 dollars
- and then there was Pams clothes..oh yeah, and a Niffty NFT for
- a mere few million.if you like conspiracy theory sites checkout
- these one below great for yup coming sports!!
- https://polishmexican.blogspot.com/2006/02/blogger-mess-up.html
- http://polishmexican.blogspot.com/2007/08/actual-polish-mexican-content.html
- https://shirazsocialist.wordpress.com/2017/12/21/mccluskey-jewish-news-interview/
- https://psychedelicdungeon.wordpress.com/2010/09/04/wikileaks-pt-2-reaction/
- https://rightsfreedoms.wordpress.com/2021/12/15/rfk-jrs-heroic-resistance-to-the-cias-continuing-covid-coup-detat/
- https://psychedelicdungeon.wordpress.com/2010/09/02/wikifreaks-pt-1-eat-pray-leak/
- https://www.independentsentinel.com/potential-whistleblower-named-but-not-proven/
- https://therapidesnote.blogspot.com/2011/04/anonymous-commenters-on-computers.html
- https://www.dialoginternational.com/dialog_international/2021/08/anti-vaxxers-in-germany-querdenker-anti-semites-neo-nazis.html
- https://www.cringely.com/2021/09/10/bobs-9-11-post-from-20-years-ago-to-a-man-with-a-hammer/
- https://ganglandireland.blogspot.com/2009/11/fat-freddie-thompson-riding-shotgun-for.html
- https://ganglandireland.blogspot.com/2009/11/gangs-of-dublin.html
- https://discyonki.blogspot.com/2011/11/man-is-in-love-waterboys.html
- https://www.afepi-ireland.com/member/smith-albert
- https://kaildganglife.blogspot.com/2011/03/prison-gangs-one-mexican-mafia-v.html
- https://tfiglobalnews.com/2021/11/22/northern-irelands-secession-from-the-united-kingdom-is-almost-a-surety-now/
- https://www.independentsentinel.com/potential-whistleblower-named-but-not-proven/
- http://www.darkpolitricks.com/2020/02/am-i-going-down-google-plug-of.html
- http://www.darkpolitricks.com/2022/05/here-comes-world-war-iii.html
- http://www.darkpolitricks.com/2021/03/is-biden-worse-than-trump.html
- http://www.darkpolitricks.com/2022/03/two-things-can-be-right-at-same-time.html
- http://www.darkpolitricks.com/2021/12/the-internet-is-dead-can-you-prove-it.html
- http://www.darkpolitricks.com/2021/09/the-uk-is-becoming-more-despotic-every.html
- http://www.darkpolitricks.com/2022/01/how-many-conspiracies-have-to-turn-true.html
- http://www.darkpolitricks.com/2022/03/the-stupidity-of-russian-sanctions.html
- http://www.darkpolitricks.com/2022/04/who-are-we-standing-with-when-we-stand.html
- http://www.darkpolitricks.com/2021/05/cia-agent-admits-why-usa-cant-have.html
- http://www.darkpolitricks.com/2018/07/israel-is-first-terrorist-state-with.html
- http://www.darkpolitricks.com/2020/07/covid19-were-loving-it.html
- http://www.darkpolitricks.com/2020/04/help-me-create-real-altnews-search.html
- Thats quite alot of sites eh!? were sure youll find interesting
- stuff there to read their files the lot, a real Burn Baby Burn list.
- infact where sure youll need this naughty daughty.
- Hang Tight.
- Lee chung.
- Big HI to Poe and Scarebear!! hoo helped compile Santas Naughty List
- HEY KAMAL TRUCKER YOU MUST THINK WE ARE REALLY STUPID OR SOMETHING.
- AGENT TALLAGHT WATCHES YOU .....
Add Comment
Please, Sign In to add comment