Bob
Bob
Repeated: Bob
I also would like it so it would do it a third time
Bob
Bob
Repeated: Bob
Bob
Repeated: Bob
I've been trying to implement this however the output send something different from what I am expecting. For example,
Jim
Jim
RepeatedJim
Jim
RepeatedJim
Bob
RepeatedJim
How on earth do I implement the correct logic? Cheers for your help.
import java.util.Scanner;
public class Repeated {
public static void main(String[] args) {
String S1 = "noData";
String S2 = "noData";
Scanner userinput = new Scanner(System.in);
System.out.println("Please enter lines of text: ");
while (userinput.hasNextLine()) {
S1 = userinput.nextLine();
if (S1.contentEquals(S2)) {
System.out.println("Repeated" + S1);
}
S2 = userinput.nextLine();
if (S1.contentEquals(S2));
{
System.out.println("Repeated" + S1);
}
if (S1.isEmpty() || S2.isEmpty())
{
System.out.println("Bye");
System.exit(0);
}
}
}
}

New Topic/Question
Reply



MultiQuote




|