0
When i put for(j=1;j<str1.length();j++) so i am getting different answers why??
public class Program { public static void main(String[] args) { String str1="ab"; byte number=0; //char name[]=str1.toCharArray(); for(int i=0;i<str1.length();i++) { for(int j=i+1;j<str1.length();j++) { if(str1.charAt(i)==str1.charAt(j)) { System.out.print(str1.charAt(i)+" "); System.out.print(str1.charAt(j)+" "); number++; break; } } } System.out.println(number); System.out.println((number==0) ? "no dublicate found" : "dublicate found"); } }
3 Réponses
+ 2
Thnx...
+ 1
for(int j = 1; j < str1.length(); j++)
<j> always initialize with a value of 1.
for(int j = i + 1; j < str1.length(); j++)
<j> initialize dynamically. Value of <j> depends on value of <i>.
0
Welcome ...