My issue: I keep getting the same errors that the while loop is illegal and the } are in the wrong places. My code: import java.util.Scanner; public class LabProgram { public static void main(String[] args) { /* Type your code here. */ Scanner scnr = new Scanner(System.in) { String s=scnr.nextLine(); while(!(s.equalsIgnoreCase("Done") || s.equalsIgnoreCase("d"))){ for(int i = s.length()-1; i>=0;i--){ System.out.print(s.charAt(i)); } System.out.println(); s = scnr.nextLine(); } } } The Problem: Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Done", "done", or "d" for the line of text. Ex: If the input is: Hello there Hey done the output is: ereht olleH yeH
My issue:
I keep getting the same errors that the while loop is illegal and the } are in the wrong places.
My code:
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
/* Type your code here. */
Scanner scnr = new Scanner(System.in) {
String s=scnr.nextLine();
while(!(s.equalsIgnoreCase("Done") || s.equalsIgnoreCase("d"))){
for(int i = s.length()-1; i>=0;i--){
System.out.print(s.charAt(i));
}
System.out.println();
s = scnr.nextLine();
}
}
}
The Problem:
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Done", "done", or "d" for the line of text.
Ex: If the input is:
Hello there Hey done
the output is:
ereht olleH yeH


Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images









