Common addition operations for JAVA

Source: Internet
Author: User

Using the scanner class, where the numeric input function uses the while loop structure to get the real number entered, and when the letter is entered, the loop is ended

Source:

Package CCC;
Import java.util.*;
public class VVV {
public static void Main (string[] args) {
System.out.println ("Please enter the number of additions required");
System.out.print ("(last input any letter end input):");
Scanner reader=new Scanner (system.in);
Double sum = 0;
int m=0;
while (Reader.hasnextdouble ())
{
Double x = reader.nextdouble ();
m = m + 1;
sum = sum + x;

}
System.out.print ("Number of inputs" +m+ "\ T and is:" +sum);
System.out.print ("\ t average is:" +sum/m);
}

}

Results:

Common addition operations for JAVA

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.