| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 996 人关注过本帖
标题:为什么两个public就无法运行了!
只看楼主 加入收藏
yynn
Rank: 1
等 级:新手上路
帖 子:279
专家分:0
注 册:2005-11-4
收藏
 问题点数:0 回复次数:3 
为什么两个public就无法运行了!
public class Element
{
    // names of the chemical elements in alphabetical order
    
    public static final String[] names = {
        "Actinium", "Aluminium", "Americium", "Antimony", "Argon",
        "Arsenic", "Astatine", "Barium", "Berkelium", "Beryllium",
        "Bismuth", "Bohrium", "Boron", "Bromine", "Cadmium", "Caesium",
        "Calcium", "Californium", "Carbon", "Cerium", "Chlorine",
        "Chromium", "Cobalt", "Copper", "Curium", "Darmstadtium",
        "Dubnium", "Dysprosium", "Einsteinium", "Erbium", "Europium",
        "Fermium", "Fluorine", "Francium", "Gadolinium", "Gallium",
        "Germanium", "Gold", "Hafnium", "Hassium", "Helium", "Holmium",
        "Hydrogen", "Indium", "Iodine", "Iridium", "Iron", "Krypton",
        "Lanthanum", "Lawrencium", "Lead", "Lithium", "Lutetium",
        "Magnesium", "Manganese", "Meitnerium", "Mendelevium", "Mercury",
        "Molybdenum", "Neodymium", "Neon", "Neptunium", "Nickel",
        "Niobium", "Nitrogen", "Nobelium", "Osmium", "Oxygen",
        "Palladium", "Phosphorus", "Platinum", "Plutonium", "Polonium",
        "Potassium", "Praseodymium", "Promethium", "Protactinium",
        "Radium", "Radon", "Rhenium", "Rhodium", "Roentgenium",
        "Rubidium", "Ruthenium", "Rutherfordium", "Samarium", "Scandium",
        "Seaborgium", "Selenium", "Silicon", "Silver", "Sodium",
        "Strontium", "Sulphur", "Tantalum", "Technetium", "Tellurium",
        "Terbium", "Thallium", "Thorium", "Thulium", "Tin", "Titanium",
        "Tungsten", "Ununbium", "Ununhexium", "Ununoctium", "Ununpentium",
        "Ununquadium", "Ununtrium", "Uranium", "Vanadium", "Xenon",
        "Ytterbium", "Yttrium", "Zinc", "Zirconium"};

    // approximate year of discovery for each element above
    
    public static final int[] years = {
        1899, 1825, 1944, 1540, 1894,
        1250, 1940, 1808, 1949, 1798,
        1753, 1975, 1808, 1826, 1817, 1860,
        1808, 1950, 1, 1803, 1774,
        1797, 1735, 1, 1944, 1994,
        1967, 1886, 1952, 1842, 1890,
        1952, 1866, 1939, 1880, 1875,
        1886, 1, 1923, 1984, 1868, 1878,
        1766, 1863, 1811, 1803, 1, 1898,
        1839, 1961, 1, 1817, 1907,
        1775, 1774, 1982, 1955, 1,
        1778, 1885, 1898, 1940, 1751,
        1801, 1772, 1958, 1803, 1774,
        1803, 1669, 1735, 1940, 1898,
        1807, 1885, 1945, 1913,
        1898, 1900, 1925, 1804, 1994,
        1861, 1844, 1964, 1879, 1878,
        1974, 1817, 1824, 1, 1807,
        1808, 1, 1802, 1937, 1782,
        1843, 1861, 1828, 1879, 1, 1791,
        1783, 1996, 2002, 2002, 2004,
        1998, 2004, 1841, 1801, 1898,
        1878, 1794, 1300, 1789};
}


public class ElementTest
{
    public static void main(String[] args)
    {
        System.out.println("The first element in the list is " + Element.names[0] + ".");
        System.out.println("It was discovered in " + Element.years[0] + ".");
        System.out.println("It has " + Element.names[0].length() + " letters.");
        System.out.println();
        
        int arrayLength = Element.names.length;
        
        System.out.println("The last element in the list is " + Element.names[arrayLength-1] + ".");
        System.out.println("It was discovered in " + Element.years[arrayLength-1] + ".");
        System.out.println();
        
        System.out.println("There are " + arrayLength + " elements in the list.");
        System.out.println("Hope his helps...");
        
        System.out.println(); System.out.println();
    }
}
搜索更多相关主题的帖子: public 运行 
2007-12-10 05:43
hwoarangzk
Rank: 4
来 自:冰封王座
等 级:贵宾
威 望:12
帖 子:1894
专家分:0
注 册:2007-7-17
收藏
得分:0 
一个文件里面只能有一个public类

I'm here, as always...
2007-12-10 09:32
baijian710
Rank: 1
等 级:新手上路
帖 子:52
专家分:0
注 册:2007-11-11
收藏
得分:0 
先写ElementTest 类,然后创建新的java类,把Element 类添加上,就行了。
2007-12-10 09:38
Toanso
Rank: 1
来 自:杭州
等 级:新手上路
帖 子:102
专家分:0
注 册:2007-10-22
收藏
得分:0 
回复 1# 的帖子
创建新的类,然后创建以对象就可以了。
2007-12-11 13:40
快速回复:为什么两个public就无法运行了!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020423 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved