Java program design fourth job content fifth job was released in October 9, for the third chapter all examples, java program design

Source: Internet
Author: User

Java program design fourth job content fifth job was released in October 9, for the third chapter all examples, java program design

Question 6: What is the day of the week when the corresponding Chinese words are output based on numbers using the judgment statement?

Directly Using an if statement

Int weekDay = 3;

If (weekDay = 1 ){

Sop ("Today is Monday ");

}

If (weekDay = 2 ){

Sop ("Today is Tuesday ");

}

If (weekDay = 3 ){

Sop ("Today is Wednesday ");

}

Use the associated if statement

If (weekDay = 1 ){

Sop ("Today is Monday ");

} Else if (weekDay = 2 ){

Sop ("Today is Tuesday ");

} Else if (weekDay = 3 ){

Sop ("Today is Wednesday ");

} Else {

Sop ("No such day ");

}

Use the if statement to do an exercise: one year has 12 months, in which spring is 3, 4, 5, summer is 6, 7, 8, autumn is 9, 10, 11 Winter is 12, 1, 2

Int month = 8; // you can enter a custom number on the keyboard.

Question 7: Use the branch statement, calculate +-*/%, and use the switch statement

int a=84,b=3;        char option='%';        switch (option)        {        case '+':            System.out.println("a+b="+(a+b));            break;        case '-':            System.out.println("a-b="+(a-b));            break;        case '*':            System.out.println("a*b="+(a*b));            break;        case '/':            System.out.println("a/b="+(a/b));            break;        case '%':            System.out.println("a%b="+(a%b));            break;        default:            System.out.println("a%b="+(a%b));            break;        }

Can the branches be freely adjusted?

Can the branch content be omitted?

Use the switch statement to do an exercise: there are 12 months in a year, in which spring is 3, 4, 5, summer is 6, 7, 8, autumn is 9, 10, 11 Winter is 12, 1, 2

Question 8: How can I analyze the output results of a program using a loop statement?

What is the difference between do while and while?

Int x = 1;

Do {

Sop ("x =" + x );

X ++;

} While (x <1 );

 

Int y = 1;

While (y <1 ){

Sop ("y =" + y );

Y ++;

}

Question 9: How can I use for to write a simple loop statement to analyze the output result of a program?

For (int x = 1; x <3; x ++)

{

Sop ("x =" + x );

}

 

For (sop ("a"); sop ("B"); sop ("c ")

{

Sop ("d ");

}

Int x = 1; for (System. out. println ("a"); x <3; System. out. println ("c") System. out. println ("d"); x ++

 

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.