This video is interpretive , So I hope you have read the content of this knowledge point , And after writing the corresponding code , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning
![]() 8 branch 22 second This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers Example 1 : if Example 2 : Multiple expressions and one expression Example 3 : if Pits that may be encountered during use Example 4 : if else Example 5 : else if Example 6 : practice -BMI Example 7 : answer -BMI Example 8 : practice - leap year Example 9 : answer - leap year if( expression 1){ expression 2; } If the expression 1 The value of is true, Just execute the expression 2
public class HelloWorld { public static void main(String[] args) { boolean b = true; // If so, print yes if(b){ System.out.println("yes"); } } }
public class HelloWorld { public static void main(String[] args) { boolean b = true; // If so, print yes if(b){ System.out.println("yes"); } } }
public class HelloWorld { public static void main(String[] args) { boolean b = false; // If there are multiple expressions , Must be enclosed in large brackets if(b){ System.out.println("yes1"); System.out.println("yes2"); System.out.println("yes3"); } // Otherwise, the expression 2 3 whether b Is it true Will be implemented if(b) System.out.println("yes1"); System.out.println("yes2"); System.out.println("yes3"); // If there is only one expression, you don't have to write parentheses , It looks simpler if(b){ System.out.println("yes1"); } if(b) System.out.println("yes1"); } }
In the first 6 that 's ok ,if There is a semicolon behind it ; and
The semicolon is also a complete expression
If b by true, Will execute this semicolon , Then print yes If b by false, Will not execute this semicolon , Then print yes such , It looks like it will print anyway yes
public class HelloWorld { public static void main(String[] args) { boolean b = false; if (b); System.out.println("yes"); } }
public class HelloWorld { public static void main(String[] args) { boolean b = false; if (b); System.out.println("yes"); } }
else If the representative is not established
public class HelloWorld { public static void main(String[] args) { boolean b = false; if (b) System.out.println("yes"); else System.out.println("no"); } }
public class HelloWorld { public static void main(String[] args) { boolean b = false; if (b) System.out.println("yes"); else System.out.println("no"); } }
else if It's multi conditional judgment
public class HelloWorld { public static void main(String[] args) { // If only if, Will execute 4 Secondary judgment int i = 2; if (i==1) System.out.println(1); if (i==2) System.out.println(2); if (i==3) System.out.println(3); if (i==4) System.out.println(4); // If used else if, Once in 18 that 's ok , Judgment established , 20 Line sum 22 The judgment of the line will not be executed , Save computing resources if (i==1) System.out.println(1); else if (i==2) System.out.println(2); else if (i==3) System.out.println(3); else if (i==4) System.out.println(4); } }
Based on the previous
Operator practice -BMI, Make improvements based on judgment :
use Scanner Collect your height and weight , And calculate your BMI What is the value BMI The formula is weight (kg) / ( height * height ) For example, Qiu Yangbo's weight is 72kg, Height is 1.69, So this classmate's BMI namely 72 / (1.69*1.69) = ? Then judge by conditions BMI Scope of , Print out whether it's overweight or normal reference resources : use Scanner How to read floating point numbers
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Account not activated
Account not activated , Limited functionality . Please click activate
This video is interpretive , So I hope you have read the content of this answer , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning
![]() 5 branch 4 second This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers
import java.util.Scanner; public class HelloWorld { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println(" Please enter your height (m):"); float height = s.nextFloat(); System.out.println(" Please enter your weight (kg):"); float weight = s.nextFloat(); float BMI = weight / (height * height); System.out.println(" Current BMI yes : " + BMI); String status = ""; if (BMI < 18.5) status = " Underweight "; else if ( BMI < 24) status = " normal range "; else if (BMI < 27) status = " Overweight "; else if (BMI < 30) status = " Mild obesity "; else if (BMI < 35) status = " Moderate obesity "; else status = " Severe obesity "; System.out.println(" The physical state is : " + status); } }
Judge whether a year is a leap year
Through Scanner Enter a year , Then judge whether the year is a leap year Leap year criteria ( Satisfy any ) 1. If it can be 4 to be divisible by , But it can't be 100 to be divisible by 2. Can be 400 to be divisible by
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Account not activated
Account not activated , Limited functionality . Please click activate
This video is interpretive , So I hope you have read the content of this answer , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning
![]() 4 branch 42 second This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers
import java.util.Scanner; public class HelloWorld { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println(" Please enter the year "); int year = s.nextInt(); if ( (0 == year % 4 && 0 != year % 100) || 0 == year % 400) System.out.println(year + " It's a leap year "); else System.out.println(year + " Not a leap year "); } }
import java.util.Scanner; public class HelloWorld { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println(" Please enter the year "); int year = s.nextInt(); if ( (0 == year % 4 && 0 != year % 100) || 0 == year % 400) System.out.println(year + " It's a leap year "); else System.out.println(year + " Not a leap year "); } }
The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .
![]()
Q & A area
2021-10-21
if Sentence selection judgment
3 One answer
sdc Jump to the problem location Answer time :2021-11-03
public class Year { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print(" Please enter the year :"); int a = sc.nextInt(); if (a % 4 == 0 && a % 100 !=0) { System.out.println(a+" It's a leap year "); }else if (a % 400 ==0){ System.out.println(a+" It's a leap year "); }else { System.out.println(a+" Not a leap year "); } } }
Hard working snail i Jump to the problem location Answer time :2021-10-30 java_lck Jump to the problem location Answer time :2021-10-25
public boolean test(int s) { if (s % 2 ==0) { return true; } else { return false; } }
The answer has been submitted successfully , Auditing . Please
My answer Check the answer record at , thank you
2021-10-16
Why else if No output ?
7 One answer
czw1999 Under review Answer time :2021-11-08
import java.util.Scanner; public class if sentence { public static void main(String[] args) { Scanner CZW=new Scanner(System.in); System.out.println(" Please enter your weight (kg):"); float a=CZW.nextFloat(); System.out.println(" Please enter your height ( rice ):"); float b=CZW.nextFloat(); float c=a/(b*b); System.out.println(" The body mass index is :"+c); if (c<18.5) System.out.println(" The physical state is : Underweight "); else if (18.5<=c&&c<24) System.out.println(" The physical state is : normal range "); else if (24<=c&&c<27) System.out.println(" The physical state is : Overweight "); else if (27<=c&&c<30) System.out.println(" The physical state is : Mild obesity "); else if (30<=c&&c<35) System.out.println(" The physical state is : Moderate obesity "); else if(35<=c) System.out.println(" The physical state is : Severe obesity "); //easy } }
275797840 Jump to the problem location Answer time :2021-11-06
use Scanner Collect your height and weight , And calculate your BMI What is the value BMI The formula is weight (kg) / ( height * height ) For example, Qiu Yangbo's weight is 72kg, Height is 1.69, So this classmate's BMI namely 72 / (1.69*1.69) = ? Then judge by conditions BMI Scope of , Print out whether it's overweight or normal
Wuyishan tea Jump to the problem location Answer time :2021-11-02
1900 It doesn't meet your above judgment , But there is no following Non conforming output , So there is no output .
Hard working snail i Jump to the problem location Answer time :2021-10-30 See you tomorrow. Jump to the problem location Answer time :2021-10-27 Spicy chicken with vegetables Jump to the problem location Answer time :2021-10-22 JieeeeE Jump to the problem location Answer time :2021-10-20
first , Not with else if No output , But no 1900 Can meet the conditions you write , The program exits naturally and normally without output results . secondly , Why not 1900 Conditions met , Because the two judgment conditions in your code are the conditions for judging leap years ( I suggest you look at the topic again , If one of the two is satisfied, it means leap year ).1900 Not a leap year , The first condition is not satisfied , The second is not satisfied . My code is attached below , Maybe not the best , But it should give you a little inspiration .
The answer has been submitted successfully , Auditing . Please
My answer Check the answer record at , thank you
2021-08-31
If the conditions are met, we will continue to implement
2021-08-24
Leap year judgment
2021-08-24
calculation BMI value
Too many questions , Page rendering is too slow , To speed up rendering , Only a few questions are displayed on this page at most . also 123 Previous questions , please Click to view
Please... Before asking questions land
The question has been submitted successfully , Auditing . Please
My question Check the question record at , thank you
|