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?

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

Read compile errors.

Edited 7 Years Ago by quuba: n/a

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.

Comments
This article has been dead for over six months. Start a new discussion instead.