1. Design ideas: first to accept multiple numbers from the keyboard, and then sum. We can use arrays to set a constant final int n;
int a "" =new int "n", then the data is received from the keyboard using Integer.parseint (), and then the output is summed.
2. Program Flowchart:
1 Introduction Package (scanner for input and joptionpane for design input box)
2 defines a constant n,final int n, which is used for array settings.
3 defines an array of int a "" =new int "n";
4 reading data from the keyboard using scanner objects or Integer.parseint ()
5 summation output
6 design box and other prompts after the main program is finished
3 Source code:
Import Javax.swing.JOptionPane;
Import Java.util.Scanner;
public class Javaargument {
public static void Main (string[] args) {
Scanner lnput=new Scanner (system.in);
String Q;
final int n;
int sum=0;
Q=joptionpane.showinputdialog ("Please input N:");
N=integer.parseint (q);
String B[]=new String[n];
int a[]=new Int[n];
for (int i=0;i<n;i++)
{int j=i+1;
B[i]=joptionpane.showinputdialog ("Please input" +j+ "number");
A[i]= Integer.parseint (B[i]);
Sum=sum+a[i];
}
Joptionpane.showmessagedialog (
NULL, "The sum is" + Sum, "Results",
Joptionpane.plain_message);
}
}
4 Experiments:
Java Course Assignment 02