accumulateelements.java
来自「《A first book of java》by Gary J.Bronson 」· Java 代码 · 共 27 行
JAVA
27 行
import javax.swing.*;
public class AccumulateElements
{
public static void main(String[] args)
{
final int NUMELS= 5;
String s1;
int i;
int total = 0;
// declare and allocate the array
int grade[] = new int[NUMELS]; // allocate the array
for (i = 0; i < NUMELS; i++) // Enter the grades
{
s1 = JOptionPane.showInputDialog("Enter a grade: ");
grade[i] = Integer.parseInt(s1);
}
System.out.print("The total of the grades");
for (i = 0; i < NUMELS; i++) // Display and total the grades
{
System.out.print(" " + grade[i]);
total = total + grade[i];
}
System.out.print(" is " + total);
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?