package com.codegym.task.task07.task0713;
import java.io.BufferedReader;z
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Playing Javarella
*/
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> mainList = new ArrayList<Integer>();
ArrayList<Integer> num3List = new ArrayList<Integer>();
ArrayList<Integer> num2List = new ArrayList<Integer>();
ArrayList<Integer>otherList = new ArrayList<Integer>();
// while(true){ //please note that it is the same syntax from the previous lecture.
// String s = reader.readLine();
// if (s.isEmpty()) break;
// mainList.add(Integer.parseInt(s));
// }
for (int i =0; i<20; i++)
{
String s = reader.readLine();
mainList.add(Integer.parseInt(s));
}
for (int x=0; x<mainList.size(); x++){
if (mainList.get(x) % 3 == 0)
num3List.add(mainList.get(x));
if (mainList.get(x) % 2 == 0)
num2List.add(mainList.get(x));
if ((mainList.get(x) % 3 != 0 && mainList.get(x) % 2 != 0))
otherList.add(mainList.get(x));
}
printList(num3List);
printList(num2List);
printList(otherList);
}
public static void printList(List<Integer> list) {
//write your code here
for (Integer x : list)
System.out.println(x);
}
}
task07.task0713: What is wrong with the while loop, though program works with for loop
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
DS
23 August 2019, 10:36
When does the while loop stop? Empty string is 21 line
0
Vikrant.
22 August 2019, 02:36
So this code works with
which is a shallow comparison
as per the examples
Why? Thoughts? 0