📄 sum1.java
字号:
// Another Sum Java class, this one creates an object of class Sum1// // This sample reads a bunch of integers entered as command line arguments// sums them up and prints the sum and average.public class Sum1 { public static void main( String args[] ) { //Create a Sum1 object Sum1 s = new Sum1(args); } // constructor Sum1(String nums[]) { // create an int array of the right size int[] ivals = new int[nums.length]; // convert each string to integer for (int i=0;i<nums.length;i++) { ivals[i]= Integer.parseInt(nums[i]); } // sum everything up int total=0; for (int i=0;i<ivals.length;i++) { total += ivals[i]; } System.out.println("Sum is " + total); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -