Java数组,它使用<a href="">

时间:2018-08-21 17:31:59

标签: java

Code that creates files with the file name as array contents, the file has word with links previous for the word before and next for the word after, at present it creates files but

the code prints

创建顺序链接

!要迭代数组只是将数组内容打印为array指定的位置,它应该将数组写数组内容作为单词进行迭代,将单词与上一个数组内容的前一个链接和下一个数组内容的下一个链接

public class WrHtmlWithLincs 
   {
    public static void main(String args[]) throws IOException 
    { 
    BufferedWriter bw = null;
    FileWriter fw = null;         

    try
    {   
        String word[];
        word = new String[14];
        word[0] = "Software";
        word[1] = "Java";
        word[2] = "Android";
        word[3] = "Code";
        word[4] = "Computer Science";
        word[5] = "Satellite Navigation";
        word[6] = "Communications";
        word[8] = "Calculator";
        word[9] = "JavaScript";
        word[10] = "Stanford";
        word[11] = "Mathematics";            

        for(String Ad : word)
        {            
        try
        {
        fw = new FileWriter("F:\\" + Ad + ".html");            
        bw = new BufferedWriter(fw);
        bw.write("<Table align='center' border='4' color = 'cyan'>");    

        bw.write("<TR>"); 

        bw.write("<TD>"); 
        bw.write("<a href=" + word[y] + ".html>");                                 
        bw.write("Previous"); 
        bw.write("</a>");  
        bw.write("</TD>"); 

        bw.write("<TD>"); 
        bw.write(word[y]); 
        bw.write("</TD>");          

        bw.write("<TD>"); 
        bw.write("<a href=" + word[y] + ".html>");                                 
        bw.write("Next"); 
        bw.write("</a>");
        bw.write("</TD>");             

        bw.write("</TR>");            
        bw.write("<Table>");                        
        }
        catch(IOException d)
        {
        d.printStackTrace();
        }
        finally
        {
        try {
            if (bw != null)
                bw.close();

            if (fw != null)
                fw.close();
        } catch (IOException d) {
            d.printStackTrace();
        }

        }          

        }   
    }                    
    catch(Exception d)
    {
        d.printStackTrace();
    }
    finally
    {
        try {
            if (bw != null)
                bw.close();

            if (fw != null)
                fw.close();
        } catch (IOException d) {
            d.printStackTrace();
        }

    }
}
}

1 个答案:

答案 0 :(得分:0)

这将为您服务。这是我能想到的最简单的魔术解决方案中最接近的东西。

将此代码粘贴到您正在工作的类中的某个位置:

%%cython
from cython.parallel import prange

cpdef int my_func(unsigned long long[::1] starts, long long[::1] values):
    cdef int i,j
    for i in prange(len(starts)-1, nogil=True):
        for j in range(starts[i], starts[i+1]):
                    # Do something with values[j]
            pass
    return 42

您可以通过执行以下操作来使用此循环:

@FunctionalInterface
public interface TriConsumer {

    abstract void consume(Object before, Object current, Object after);

}

public static final forContext(Object[] arr, TriConsumer consumer){
    if (arr == null) {
        return;
    }
    for (int i = 0; i < arr.length; i++){
        consumer.consume(i == 0 ? null : arr[i - 1], arr[i], i == arr.length - 1 ? null : arr[i + 1]);
    }
}

编辑:我认为这需要Java 8或更高版本?