+ 6
Error
I can't understand why last line is unreachable https://code.sololearn.com/c6onDSja2429/?ref=app
9 Respuestas
+ 11
● the condition in while() loop is always true , so the loop will never over , so print statement will never be reached .
+ 7
Exit condition from the loop is missing.
Now it's always true so it always executes the loop.
Tl dr: Infinite loop
+ 2
Thanks to all of you 😊😊😊
+ 2
Linda the program doesn't give the desired output..
When I enter "we are learning java"
It gives output we...
And Bennett Post I can't use your program as I have not learn array in school till now ..
+ 2
import java.util.*;
public class Main
{
public static void main(String[] args)
{
System.out.println("enter a line=");
Scanner c = new Scanner(System.in);
String s=c.nextLine();
Scanner c2=new Scanner(s);
String w,lg="";
while(c2.hasNext())
{
w=c2.next();
if(w.length()>lg.length())
lg=w;
}
System.out.println(lg+""+lg.length());
}
}
I found this program on internet but I cannot understand what is the use of the two extra line , I mean what is there need
these two lines:
" String s=c.nextLine();
Scanner c2=new Scanner(s); "
+ 2
Thanks to all of you 😊😊😊
Here's my updated program...
https://code.sololearn.com/c1TYv7uGUQxA/?ref=app
😄😄😄
+ 1
But I don't know how to use break there ...
Can anyone give me a program written...😅😅😅
0
This code is edited with adding break and perfectly run
https://code.sololearn.com/cUj0oAR06Yy6/?ref=app
0
U must add a break statement to get out of the infinite while loop