Java Course Assignment 02

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.