First, the Java Foundation

Source: Internet
Author: User

In the morning again to review the basics of Java, including write a Hello World, learn the double-precision floating point data control bit output, and write a leap year judgment, finally learned the loop, wrote 1-100 cumulative sum, for a result, for a variety of writing methods.

For the output hello with System.out.println, it's OK,

There are three ways to control the output of double-progress floating-point data,

1, in string format

System.out.println (String.Format ("%.2f", a));

2, with printf

System.out.printf ("%.9f", a);

3, with DecimalFormat

DecimalFormat format = new DecimalFormat ("#.0000");

System.out.println (Format.format (a));

Leap year words, the general idea, is divisible by 4 at the same time is divisible by 100, divisible by 400.

&& symbol Yes or, | | IS and

The last is the cycle, there are three ways of circulation, while,do......while,for, for 1-100 accumulation,

1, with while

int a=0,i=1;

while (i<=100)

{

A=a+i;

i++;

}

System.out.println (a);

2,do......while

int a=0,i=1;

Do

{

A=a+i;

i++;

}

while (i<=100);

System.out.println (a);

3,for

int a=0,i;

for (i=1;i<=100;i++)

{

A=a+i;

}

System.out.println (a)

All of this was done this morning.

First, the Java Foundation

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.