问题描述
应打印数组内容的代码,打印数组字内容为secuence但不打印卫星内容为数字,打印cs后四次迭代打印卫星然后经过四次迭代导航然后Honmgyan,应打印
CS
软件
卫星
Java
导航
Android
红岩
代码
Code that should print array contents , prints the array word contents as secuence but does not prints the satellite contents as numbers, prints cs and after four iterations prints satellite then after four iterations Navigation and then Honmgyan, should print
CS
Software
Satellite
Java
Navigation
Android
Hongyan
Code
public class ReadAndWriteFromArrays
{
public static void main(String[] args)
{
BufferedWriter bw = null;
FileWriter fw = null;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String word[];
word = new String[4];
word[0] = "Software";
word[1] = "Java";
word[2] = "Android";
word[3] = "Code";
String Satellite[];
Satellite = new String[4];
Satellite[0] = "CS";
Satellite[1] = "Satellite";
Satellite[2] = "Navigation";
Satellite[3] = "Hongyan";
for(String Ad : Satellite)
for(String Ac : word)
{
String FILENAME = "F:\\"+ Ad +".html";
try
{
System.out.print("Word: " + Ad);
String French = reader.readLine();
System.out.print("Words:" + Ac);
String Android = reader.readLine();
System.out.print("a: ");
String a = reader.readLine();
System.out.print("b: ");
String b = reader.readLine();
}
catch(IOException d)
{
d.printStackTrace();
}
finally{
try {
if (bw != null)
bw.close();
if (fw != null)
fw.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
try {
if (bw != null)
bw.close();
if (fw != null)
fw.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
我尝试了什么:
为循环更改,还有另一种方法可以写几个for循环,以便将不同的数组内容打印为编号
What I have tried:
changed for loops , there is another way to write several for loops so that different array contents are printed as numbered
推荐答案
for (int i = 0; i < word.length; i++)
{
System.out.println(Satellite[i]);
System.out.println(word[i]);
}
以上内容会根据您提问中的要求打印出来。
The above would print it out as requested in your question.
for(int i = 0; i < 4; ++i)
{
// String FILENAME = "F:\\"+ Ad +".html";
System.out.println("Words:" + Satellite[i]);
System.out.println("Word: " + word[i]);
}
这篇关于Java for循环!会打印数组内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!