I must do an exercise from the book. The exercise is:
Write a filter that reads in a sequence of integers and prints the integers, removing repeated values that appear consecutively. For example , if the input is 1 2 2 1 5 1 1 7 7 7 7 1 1 1 1 1 1 1 1 1 , your program should print 1 2 1 5 1 7 1.
public class B1_5_6
{
public static void main(String[] args)
{
int waarde1 = StdIn.readInt(); //eerste waarde die je invult
String reeks = waarde1 + " "; //die mag dus altijd geprint worden
while (!StdIn.isEmpty())
{
int waarde2 = StdIn.readInt(); //volgende waardes die je invult
if (!(waarde1 == waarde2)) // als die niet hetzelfe is dan de voorgaande waarde, mag je dat getal ook uitprinten
{
waarde1 = waarde2;
reeks = reeks + waarde2 + " "; // reeks is de waardes die al uitgeprint mogen worden en daar komt de nieuwe ingevulde waarde bij
}
}
StdOut.println(reeks);
}
}
My question is:
I do not understand the second line: String reeks = waarde1 + " "; //die mag dus altijd geprint worden
What does this " " mean? It means you can fill whatever you want in right? Or does it mean empty??
Maybe a simple thing to understand for people, but I do not understand this hole line and why you make it. I get it that you need the numbers in sequence after each other without getting a number equal to the number in front of it.. like 2 2 makes 2. but I do not understand what this basic
" " mean. i made alot of exercises alrdy but I still do not get what this means, and I can not find it anywhere.
Thanks for the detailed description and explanations.