- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 50288 个
- 通用积分
- 83.6306
- 学术水平
- 253 点
- 热心指数
- 300 点
- 信用等级
- 208 点
- 经验
- 41518 点
- 帖子
- 3256
- 精华
- 14
- 在线时间
- 766 小时
- 注册时间
- 2006-5-4
- 最后登录
- 2022-11-6
|
|
- public class DemoArray
- {
- public static void main(String[] args)
- {
- 2. On a new line, declare and create an array that can hold four double values
- by typing the following:
- double[] salaries = new double[4];
- 3. One by one, assign four values to the four array elements by typing the
- following:
- salaries[0] = 6.25;
- salaries[1] = 6.55;
- salaries[2] = 10.25;
- salaries[3] = 16.85;
- 4. To confirm that the four values have been assigned, display the salaries one
- by one using the following code:
- System.out.println("Salaries one by one are:");
- System.out.println(salaries[0]);
- System.out.println(salaries[1]);
- System.out.println(salaries[2]);
- System.out.println(salaries[3]);
- 5. Add the two closing curly braces that end the main() method and the
- DemoArray class.
- 6. Save the program as DemoArray.java. Compile and run the program.
- The program’s output appears in Figure 8-2.
复制代码
|
|