0
I want to compare two Strings character by Character...Whats wrong with my code? Pls help ..
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc=new Scanner (System.in); String s=sc.nextLine (); String s1=sc.nextLine (); int l=s.length (); int i=0,count=0; Boolean flag=true; while (i <l) { if (s.charAt (i)!=s1.charAt (i)) { flag=false; break; } } System.out.print (b); } }
2 odpowiedzi
+ 4
You consider equals a library method, but not charAt() or nextLine()? 😜
Anywho, it's an infinite loop.
(If s has a length).
'b' is also undefined, in your print statement.
I recommend using a for loop instead.
0
The only mistake was i hadn't increment i##Silly Me...it goes wrong while I edited it after posting here...