Package com.java.learing;
Import Java.awt.TextField;
Import Java.io.File;
Import java.io.FileNotFoundException;
Import java.io.IOException;
Import Java.util.Scanner;
Import Javax.swing.plaf.synth.SynthStyle;
/**
* @author Yufeifei
* @version November 21, 2017 8:47:56
* Practice Harvesting:
* 1. The switch statement must be followed by a constant, and the default statement is executed if all cases are not met;
* 2, can combine multiple case, output a result;
* 3, ++i is first added in the assignment. i++ is first assigned to + +;
* 4, you can add a label in front of the For loop, the following can be used to exit the large cycle directly;
*/
/** using a switch statement to calculate the discount based on the message amount */
public class TestDemo13 {
public static void Main (String agrs[]) {
System.out.println ("Please enter your spending amount:");
Scanner scan = new Scanner (system.in);
Float money = scan.nextfloat ();//Amount
String rebate = "";//Discount
if (Money > 200) {
int grade = (int) money/200;//level
Switch (grade) {
Case 1:
Rebate = "95 percent";
Break
Case 2:
rebate = "90 percent";
Break
Case 3:
rebate = "85 percent";
Break
Case 4:
rebate = "80 percent";
Break
Default is used when the default statement is executed when all case statements do not satisfy the condition in the switch statement
Default
rebate = "Full 400 minus 40!" ";
Break
}
System.out.println ("Your total consumption amount is:" + money);
System.out.println ("You will enjoy" + rebate + "Offer! ");
}else{
SYSTEM.OUT.PRINTLN ("The amount you spend does not meet the discount requirements Oh ~");
}
}
}
/** determine the season for users to enter the month */
public class testdemo13{
public static void Main (String agrs[]) {
Scanner scan = new Scanner (system.in);//Create Scanner
System.out.println ("Please enter a month, I can tell you which season it belongs to:");//user input
int month = Scan.nextint ();//Receive user input month
Switch (month) {
Case 12:
Case 1:
Case 2:
System.err.println ("The month you entered belongs to winter. ");
Break
Case 3:
Case 4:
Case 5:
System.err.println ("The month you entered belongs to spring.") ");
Break
Case 6:
Case 7:
Case 8:
System.out.println ("The month you entered belongs to autumn.") ");
Default
System.out.println ("Do you have a" + month + "month?) ");
Break
}
}
}
/** loop through an array with a while loop statement and a self-increment operator */
public class testdemo13{
public static void Main (String agrs[]) {
Creating an array of birds
String[] aves = new string[]{"Egret", "Oriole", "Parrot", "Crow", "Magpie", "cuckoo", "Turtle Dove", "Lark"};
int index = 0;//Create an index variable
SYSTEM.OUT.PRINTLN ("There are a lot of birds in my garden, about including:");
while (Index < aves.length) {
System.out.println (aves[index++]);//after + + is the first value, in addition. Before + + is added first, in the value
}
}
}
/** terminating the loop body */
public class testdemo13{
public static void Main (String agrs[]) {
System.out.println ("\ n----------An example of a single-layer loop----------");
Create an array
string[] array = new string[]{"Egret", "Oriole", "Eagle", "Parrot", "Crow", "Eagle", "Magpie", "cuckoo", "Turtle Dove", "Lark"};
System.out.println ("Before you find the first eagle, tell me what the birds are.") ");
for (String String:array) {
if (String.Equals ("Eagle"))
Break
System.out.println ("There:" + string + "");
}
System.out.println ("\ n---------Terminal Double-cycle example---------");
int[][] myscores = new int[][]{{67,78,63,22,66},{55,68,78,95,44},{95,97,92,93,81}};
System.out.println ("Baby This exam results: \ n math \ t chinese \ \ \ \ \ \ \ \ \ \ \ \ \");
No1:for (int[] is:myscores) {//using a Tagged break statement, you can forcibly exit the multilayer loop
for (element variable x: Traverse object obj)
SYSTEM.ERR.PRINTLN (i + "t");
if (I < 60) {
SYSTEM.ERR.PRINTLN (i + "fail");
Break No1;
}
}
System.out.println ();
}
}
}
Java Exercise-006