In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what are the three process control statements in Java". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the three process control statements in Java"?
Sequential statement
Sequence, as the name implies, means that the program is executed from top to bottom.
Public class User {public static void main (String [] args) {String name = "hacker"; int age = 18; String happy = "Learning Java"; System.out.println ("name:" + name); System.out.println ("Age:" + age); System.out.println ("hobby:" + happy);}}
The running results are as follows:
Select statement
If else
If (expression) {
Statement block 1
}
Else {
Statement Block 2
}
First judge the expression, when the value of the expression is true, execute statement block 1, otherwise, execute statement block 2
Take a chestnut.
Enter the score from the console. If the score is greater than or equal to 60, the output score passes, otherwise the output score fails.
Import java.util.Scanner;public class User {public static void main (String [] args) {var sc = new Scanner (System.in); System.out.print ("Please enter score:"); float score = sc.nextFloat (); if (score > = 60) {/ / if score > = 60, pass System.out.printf ("pass:% 3.1f", score) } else {/ / otherwise fail System.out.printf ("fail:% 3.1f", score);}
The running results are as follows:
Nesting of if else
Multiple conditions need to be judged, and nesting of if else is needed.
The basic format is as follows:
If (expression 1) {
Statement block 1
} else if (expression 2) {
Statement Block 2
}
Else {
Statement Block 3
}
First, judge expression 1, when expression 1 holds execution statement block 1, does not hold judgment expression 2, if expression 2 establishes execution statement block 2, execution statement block 3 is not established.
Take a chestnut.
Enter the score from the console, fail when the score is less than 60, pass when the score is between 60 and 90, and excellent when the score is greater than 90
Import java.util.Scanner;public class User {public static void main (String [] args) {var sc = new Scanner (System.in); / / System.out.print ("Please enter grades:"); float score = sc.nextFloat (); if (score)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.