Java Course first time job

Source: Internet
Author: User

3.1 Print out the number of daffodils in the 1~10000:

Program code:

 Public class Shuixian {    publicstaticvoid  main (string[] args)      {           for (int i=1;i<=10000;i++)      {       int  Ge,shi,bai;      Bai=i/100;      Shi= (i-baiwei*100)/10;      GE=i-bai*100-shi*10;        if (i==ge*ge*ge+shi*shi*shi+bai*bai*Bai)       {            System.out.println (i);      }}}}

Run:

3.2 To complete the exchange of two integer contents through code

Program code:

 Public classzhengjiaohuan{ Public Static voidMain (string[] args) {intA=1; intb=2; inttemp; System.out.println ("Before exchange A:" +a); System.out.println ("Before Exchange B:" +b); Temp=A; A=b; b=temp; System.out.println ("After exchange A:" +a); System.out.println ("After Exchange B:" +b); }}

Run:

3.3 Given three numbers, find the maximum value in three numbers and output

Program code:

 Public classmaxnum{ Public Static voidMain (string[] args) {intA=1; intb=2; intC=3; System.out.println ("Three numbers 1, 2, 3\n"); if(a>b&&a>c) {System.out.println (a); }            Else if(c>a&&c>b) {System.out.println (c); }            ElseSystem.out.println (b); }}

Run:

3.4 To determine whether a number is divisible by 3, 5, and 7 at the same time

Program code:

 Public class zhengchu{    publicstaticvoid  main (string[] args)    {          int i =;        System.out.println ("Judging number");         if (i%3==0&&i%5==0&&i%7==0)        {             System.out.println (i+ "can be divisible by 3,5,7")        ;        } Else         {            System.out.println (i+ "cannot be divisible by 3,5,7");     }}}

Run:

3.5 using the While loop, Do......while Loop and for loop to find the summation of 100~200 and

1.while

Program code:

  

 Public class whilexun{    publicstaticvoid  main (string[] args)    {               int x=100,sum=0;             while (x<=200)        {                  + =x;                  X+ +;          }            System.out.println ("100-200 cumulative result is:" +sum);}     }

Run:

  

2.do......while

Program code:

 Public class dowhile{    publicstaticvoid  main (string[] args)    {          int x=100,sum=0;          Do {            sum+ =x;            X++        ;        }  while (x<=200);        System.out.println ("100-200 cumulative result is:" +sum);}    }

Run:

  

3.for

Program code:

 Public class forxun{    publicstaticvoid  main (string[] args)    {        int sum=0;          for (int x=100;x<=200;x++)        {            sum+ =x;        }        System.out.println ("100-200 cumulative result is:" +sum);}    }

Run:

  

3.6 Finding the value of 13-23+33-43+......+973-983+993-1003

Program code:

 Public classshulie{ Public Static voidMain (string[] args) {intsum = 0;  for(inti=1;i<=100;i++)        {                   if(i%2==0) {sum-= I*10+3; }                   Else{sum+ = I*10+3;       }} System.out.println (sum); }}

Run:

3.7 exchange of two numbers

Program code:

 Public classjiaohuan{ Public Static voidMain (string[] args) {Doublea=2.345; Doubleb=3.456; Doubletemp; System.out.println ("Before exchange A:" +a); System.out.println ("Before Exchange B:" +b); Temp=A; A=C; b=temp; System.out.println ("After exchange A:" +a); System.out.println ("After Exchange B:" +b); }}

Run:

Java Course first time job

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.