Hi,
can anyone tell me or see, where i made a mistake. Because the fourth condition fails and i print the elements of the list each in one line. What should i do more?
Best regards
Steffen
package de.codegym.task.task07.task0720;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Gerade noch rechtzeitig gemischt
*/
class Debug{
public static boolean debug = false;
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//schreib hier deinen Code
if(Debug.debug){
System.out.println("Please enter a number for n.");
}
Integer n = Integer.parseInt(reader.readLine());
if(Debug.debug){
System.out.println("n: " + n);
}
if(Debug.debug){
System.out.println("Please enter a number for m.");
}
Integer m = Integer.parseInt(reader.readLine());
if(Debug.debug){
System.out.println("m: " + m);
}
ArrayList<String> input = new ArrayList<String>(n);
readFromConsole(input);
if(Debug.debug){
System.out.println("Output the list before the manipulation");
output(input);
}
manipulation(input, n, m);
if(Debug.debug){
System.out.println("Output the list after the manipulation");
}
output(input);
}
public static void readFromConsole(ArrayList<String> arl){
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> input = arl;
String tmp = "";
while(true){
try{
tmp = in.readLine();
}catch(Exception e){
System.out.println("Readerror");
}
if(Debug.debug){
System.out.println("tmp: " + tmp);
}
if(tmp == null){
break;
}
else{
input.add(tmp);
if(Debug.debug){
System.out.println("Added: " + input.get(input.size()-1));
}
}
}
}
public static void output(ArrayList<String> list){
for(String s : list){
System.out.println(s);
}
}
public static void manipulation(ArrayList<String> list, Integer n, Integer m){
ArrayList<String> input = list;
for(int l = 0; l < m; l++){
if(Debug.debug){
System.out.println("l: " +l);
}
String help = input.get(0);
input.remove(help);
if(Debug.debug){
System.out.println("Removed succesfull " + help + " from the beginning of the list and added to the end");
}
input.add(help);
if(Debug.debug){
System.out.println("l: " + help);
}
}
}
}