Java understands if… Else if statement through scanner


This article mainly introduces Java’s understanding of if… Else if statements through scanner. The example code in this article is very detailed, which has a certain reference learning value for your study or work. You can refer to the following for friends who need it

Use the scanner class (console input) to recognize the if… Else if statement

If…. else if is a continuous conditional statement

It can be used when there are multiple judgment conditions

When to use: when multiple conditions are the same as interval division

0-59 points fail 60-80 points good 81-90 points great 91-100 points super good other conditions are illegal

import java.util.Scanner;

public class Test {

  public static void main(String[] args) {
    Scanner sc=new Scanner(;
    System. Out. Println ("how many marks did you get in this exam? "";
    //Enter your score information. Note that the score of type is decimal, so you can't use integer type. You can use floating point type
    float chengji=sc.nextFloat();
    //How did you do in the exam?
    //Symbol & & indicates yes and||indicates yes or
    //If the score is greater than or equal to 0 and the score is less than 60
    //Fail output
    if (chengji>=0&&chengji<60) {
      System. Out. Println ("you failed, why don't you work hard?";  
    //If the score is 60 or more and the score is 80 or less
    //You passed the grade output
    else if(chengji>=60&&chengji<=80){
      System. Out. Println ("you passed! "";
    //If the score is greater than 80 and the score is less than or equal to 90 
    //You're doing great output
    else if (chengji>80&&chengji<=90) {
      System. Out. Println ("your grades are great! "";
    //If the score is greater than 90 and the score is less than or equal to 100
    //Your results are excellent
    else if (chengji>90&&chengji<=100) {
      System. Out. Println ("your score is super good, come to be a programmer! "";
    //Any of the above conditions are excluded. The input information is illegal
    else {
      System. Out. Println ("the score information you entered is illegal");

It is convenient to understand the characteristics of if… Else if statement with input and output

The above is the whole content of this article. I hope it will help you in your study, and I hope you can support developepaer more.