Home /
Expert Answers /
Computer Science /
public-static-void-main-string-args-scanner-scnr-new-scanner-system-in-string-datastring-pa352
(Solved): public static void main(String[] args) \{ Scanner scnr = new Scanner(System.in); String datastring; ...
public static void main(String[] args) \{ Scanner scnr = new Scanner(System.in); String datastring; int i; dataString =scnr. nextLine(); l? Your code goes here */ for ( i=0; i< dataString. length ()?1;++i){ if ( i ! dataString.charAt (i)) \{ System.out.print(dataString.charAt(i)); \} \} \}
A for loop iterates through indices dataString.length() - 1 down to 0 of dataString to output dataString.charAt(i) at each index i. If i is not the first index of dataString, then a plus ('+') is output. Ex: For input Zoe, the characters output in reverse order are 'e', 'o', and 'Z'. A plus ('+') is output after each character except the last. Thus, the output is: e+o+Z Not all tests passed. ×1 : Compare output ? Exception in thread "main" java.util.NoSuchElementException: No line found at java.base/java.util. Scanner.nextLine (Scanner.java: 1651) at OutputElements.main (OutputElements.java:17)