I have this code:

/*
 
package lab;


public class Main {

   
    public static void main(String[] args) {
        int t=0;
        int h=0;
        int w=0;
        String Name="http://hcmiu.edu.vn/mail/cuem";
        char[] ch=new char[Name.length()];
        for(int i=0;i<Name.length();i++){
            ch[i]=Name.charAt(i);
             for(int j=0;j<Name.length();j++){
            if((ch[j]=='/')&&(ch[j+1]=='/')&&(Character.isLetter(ch[j+2]))){
                t=j+2;
                System.out.println(t);
                 h=Name.indexOf('/', j+3);
                
            }
            
             }
             
        }
        System.out.println(Name.subSequence(t, h));
    }

}

This code run correctly.But when i dont use the second for loop.i couldnt work.I dont know? plz give me the answer.

/*
 

package lab;

public class Main {

  
    public static void main(String[] args) {
        int t=0;
        int h=0;
        int w=0;
        String Name="http://hcmiu.edu.vn/mail/cuem";
        char[] ch=new char[Name.length()];
        for(int i=0;i<Name.length();i++){
            ch[i]=Name.charAt(i);
            
            if((ch[i]=='/')&&(ch[i+1]=='/')&&(Character.isLetter(ch[i+2]))){
                t=o+2;
                System.out.println(t);
                 h=Name.indexOf('/', j+3);
                
            }
            
                   
        }
        System.out.println(Name.subSequence(t, h));
       
    }

}

Why do i need the second for loop?

Recommended Answers

All 4 Replies

Second code:
Line 19: o ???
Line 21: j ???

Read compile errors.

line 19: 0=j
line 21: replace j =i
sorry i type incorrectly.
So now,could you run and show me why its wrong.thanks

In one loop
for(int i=0;i<Name.length();i++){
ch = Name.charAt(i);
.....
}
for current i , are only defined values ch[0]......ch[i-2]..ch[i-1]...ch
but no ch[i+1] or ch[i+2] .They will set in the the future course of the loop.

commented: nice +4

Oh.i understand now.Thanks for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.