0

I am getting a fault in solving the code coach.

I have done the flowing word code coach by myself when I was doing it in code playground and it ran well even I checked it on a compiler and that time it also ran well but when I copied it and pasted it in the code coach that time it is getting mistakes. I tried to check the conditions of the code coach in the code playground but no faults. Idk why it is happening 😢☹️ https://code.sololearn.com/cks7Fhgfy00h/?ref=app

21st Mar 2023, 3:51 AM
五条悟 ♡
五条悟 ♡ - avatar
5 Réponses
+ 2
五条悟 it is unnecessary to go to the next loop when you have already known b is false you should break the loop then ``` if((s.charAt(i-1))==(s.charAt(i+1))) b=true; else { b=false; break; } ```
21st Mar 2023, 5:27 AM
o.gak
o.gak - avatar
+ 2
Thank you sooo much o.gak and Solo ☺️
21st Mar 2023, 6:48 AM
五条悟 ♡
五条悟 ♡ - avatar
+ 1
try to comment out this line: `System.out.println(s);`
21st Mar 2023, 5:06 AM
o.gak
o.gak - avatar
+ 1
import java.util.*; public class Program { public static void main(String[] args) { Scanner in=new Scanner(System.in); //System.out.print("Enter a String: "); String s=in.nextLine(); //System.out.println(s); s=s.trim(); String wd=""; boolean b=false; for(int i=0;i<s.length();i++) { char ch=s.charAt(i); if(ch==' ') { if((s.charAt(i-1))==(s.charAt(i+1))) b=true; else{ b=false; break; } } else wd=wd+ch; } //if(b==true) //System.out.println("Flowing Words"); //else System.out.println(b); } }
21st Mar 2023, 5:56 AM
Solo
Solo - avatar
0
o.gak I have replaced the flowing words output to true and false and removed all the unnecessary parts but still it is showing that there is a mistake I have removed the line numbers:- 1, 6, 7, 9 and changed line 8 to String s=""; but still 😩
21st Mar 2023, 5:12 AM
五条悟 ♡
五条悟 ♡ - avatar