|
查看: 1148|回复: 9
|
Java 高手~这题要怎么做?
[复制链接]
|
|
|
本帖最后由 cy冠 于 29-4-2012 11:50 PM 编辑
我JAVA才刚起步,什么都不会。这个要怎么做?
i) Declares a String array initialized with the following strings: “Red”,
“Green”, “Blue” and “Yellow”.
ii) Write a loop that displays the contents of each element in the array that
you declared in (i).
iii) Write code that displays the total length of all the strings in the array that
you declared in (i).
谢谢各位大大 |
|
|
|
|
|
|
|
|
|
|
发表于 22-4-2012 11:14 PM
|
显示全部楼层
|
你的课本肯定有类似的example,不然就上网找 java array |
|
|
|
|
|
|
|
|
|
|
发表于 23-4-2012 09:33 AM
|
显示全部楼层
public class Test {
public static void main(String args[]) {
String[] array = {"Red", "Green", "Blue", "Yellow"};
int len = 0;
for(String color : array) {
len += color.length();
System.out.println(color);
}
System.out.println("Total length: "+len);
}
} |
|
|
|
|
|
|
|
|
|
|
发表于 23-4-2012 09:33 PM
|
显示全部楼层
本帖最后由 jambo123 于 23-4-2012 09:42 PM 编辑
public class Test {
public static void main(String args[]) {
String[] array = {"Red", "Green", "Blue", "Yellow"};
int len = 0;
for(String color : array) {
len += color.length();
System.out.println(color);
}
System.out.println("Total length: "+len);
}
}
use java applet now java@@ |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 23-4-2012 09:35 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 23-4-2012 09:44 PM
|
显示全部楼层
回复 4# jambo123
对~
Using Java Applet ,display the colors from the array, the placement of the colors can be anywhere on the applet.
要怎么做才对~ |
|
|
|
|
|
|
|
|
|
|
发表于 23-4-2012 09:47 PM
|
显示全部楼层
回复 5# cy冠
根据你的题目做的。。结果应该是对的吧!除非我理解错误咯! 第一是一个String array 有 Red, Yellow ......
然后把array display 出来,
再算出total所有words的length。 是这样的意思吧! |
|
|
|
|
|
|
|
|
|
|
发表于 23-4-2012 10:32 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 24-4-2012 07:54 PM
|
显示全部楼层
回复 8# weeshin
i) Declares a String array initialized with the following strings: “Red”,
“Green”, “Blue” and “Yellow”.
ii) Write a loop that displays the contents of each element in the array that
you declared in (i).
iii) Write code that displays the total length of all the strings in the array that
you declared in (i).
Using Java Applet ,display the colors from the array, the placement of the colors can be anywhere on the applet.
不好意思我以为我写清楚了
谢谢你 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 25-4-2012 08:32 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|