佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1148|回复: 9

Java 高手~这题要怎么做?

[复制链接]
发表于 22-4-2012 11:02 PM | 显示全部楼层 |阅读模式
本帖最后由 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).

谢谢各位大大
回复

使用道具 举报


ADVERTISEMENT

发表于 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 | 显示全部楼层
回复 3# weeshin

我这样简单吗?
回复

使用道具 举报

 楼主| 发表于 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.


要怎么做才对~
回复

使用道具 举报

Follow Us
发表于 23-4-2012 09:47 PM | 显示全部楼层
回复 5# cy冠


  根据你的题目做的。。结果应该是对的吧!除非我理解错误咯!  第一是一个String array 有 Red, Yellow ......
  然后把array display 出来,
  再算出total所有words的length。 是这样的意思吧!
回复

使用道具 举报

发表于 23-4-2012 10:32 PM | 显示全部楼层
回复 6# cy冠


   请把你的题目写清楚!
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 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 | 显示全部楼层
有谁可以帮忙?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 29-10-2025 06:59 AM , Processed in 0.107921 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表