Home > Back-end >  Small white learning Java (only to record the learning process - the third day)
Small white learning Java (only to record the learning process - the third day)

Time:09-29

Today is to learn Java code on the third day, today's study is focused on the switch case and circulation structure , in the afternoon while loop and the do while loop using a little, so the focus to review it again at night, today didn't finish writing, note upload tomorrow,
SAO lei teacher lecture interesting, to a great , found SAO lei teacher, for example, all love to use to eat, have the suspicion of version  , for example for

The class Demo4 {
Public static void main (String [] args) {
//need a variable of type int variable names here choose
Int choose=0;
Scanner sc=new Scanner(System.in);

//display menu
System. The out. Println (" welcome to SAO lei 12 Michelin star restaurant ");
System. The out. Println (" 1. Five shun zhai duck ");
System. The out. Println ("/2. Chongqing sichuan hot pot ");
System. The out. Println (" 3. Rolling face ");
System. The out. Println (" 4. Roast lamb ");
System. The out. Println (" 5. Buddha jumps over the wall (God Use VPN) ");
Choose=sc. NextInt ();

//use the switch case processing data, need to deal with the data is stored in the
//choose variable, the switch case structure processing for choose
The switch (choose) {
//case 1 is used for processing data in choose 1
the condition of theCase 1:
//handling
System. The out. Println (" five shun zhai duck 82 RMB ");
//out of the switch case structure
break;
Case 2:
System. The out. Println (" chongqing 180 RMB/sichuan hot pot ");
break;
Case 3:
System. The out. Println (" rolling face 5 RMB ");
break;
Case 4:
System. The out. Println (" roast lamb chops 65 RMB ");
break;
Case 5:
System. The out. Println (" Buddha jumps over the wall (God Use VPN) 998 RMB ");
break;
//above all Case under the condition of not running, will perform the default
//keep handling
Default:
System. Out.println (" sorry, you choose wrong!!!!!! ");
break;
}
}
}

The class Demo13 {
Public static void main (String [] args) {
/*
A variable type int is needed here, as users choose
The variable name choose
*/
Int choose=0;
/*
Calculate the total price, int type, variable called total
*/
Int total=0;
/*
Prepare a Scanner type variable, used to get the user from the keyboard
Input data
*/
Scanner sc=new Scanner(System.in);

System. The out. Println (" welcome to SAO lei old pub ");
System. The out. Println (" 1. Qingdao beer 8 RMB ");
System. The out. Println (" 2. Wild, 88 RMB ");
System. The out. Println (" 3. Jiang Xiaobai 25 RMB ");
System. The out. Println (" 4. WuSu 6 RMB ");
System. The out. Println (" 5. 1664 RMB 18 ");
System. The out. Println (" 6. Order ");
/*
User input 6 end loop, if not 6, continue to cycle
*/
While (choose! {
=6)
Choose=sc. NextInt ();

The switch (choose) {
Case 1:
System. The out. Println (" 1. Qingdao beer 8 RMB ");
Total +=8;
break;
Case 2:
System. The out. Println (" 2. Wild, 88 RMB ");
Total +=88;
break;
Case 3:
System. The out. Println (" 3. Jiang Xiaobai 25 RMB ");
Total +=25;
break;
Case 4:
System. The out. Println (" 4. WuSu 6 RMB ");
Total +=6;
break;
Case 5:
System. The out. Println (" 5. 1664 RMB 18 ");
Total +=18;
break;
Case 6:
System. The out. Println (" 6. Order ");
break;
Default:
System. The out. Println (" select error ");
break;
}
}

System. The out. Println (" this consumption: "+ total);
}
}
  • Related