Using Java to write a program to input 4 integers output 4 integers and

Source: Internet
Author: User

Source:

/*duo Ya fan*//*2015 9 23 */* for entering 4 integers and outputting 4 integers and/import java.util.*; public class Jisuan {public static void main (String args[]) {int count;//count used to denote the number of double next,sum;       The next,sum is used to store the input 4 integers and 4 integers respectively.       The sum=0;//initializes the sum.       Scanner SC =new Scanner (system.in);//define a Scanner object, Scanner is a simple scanner that uses regular expressions to parse basic types and character types to read 4 numbers of input       System.out.println ("Please enter 4 integers:"); for (count=0;count<4;count++)//{next=sc.nextint ();//The method that calls the class's Nextint () in a loop statement reads the number of inputs and places it in next Su m+=next;//adds each number of inputs to sum} System.out.println ("4 integers" and "+sum"); The sum output}}

Program Run Result:

Program Design ideas: First define a series of variables, count is used to represent the number of input integers, next is used to hold the input of each number, sum to hold 4 integers, and define a scanner object, Scanner is a simple text scanner that uses regular expressions to parse basic types and strings to read integers entered by the user. The Nextint () method of the class is called in the Recycle statement, the integer entered by the user is read, placed in next, and then added in sum, and finally 4 integers are evaluated through a loop.

Program Block diagram:

Program Block diagram:

Using Java to write a program to input 4 integers output 4 integers and

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.