精品国产一区二区三 , 亚洲综合五月 , 俄罗斯特级高清毛片免费 , 激情福利,久久久日本,欧美一三区,欧美黄色大片久久

java語言

JAVA中的if語句的使用

時(shí)間:2025-05-23 09:30:07 java語言 我要投稿

JAVA中的if語句的使用

  在這里我教一下大家JAVA語言中IF語句的使用方法,在JAVA,if語句使用方法同其他語言相似卻又不同,在下面我給大家分析一下。

  1、頭文件、定義函數(shù)、輸出字符串、對變量賦值;定義輸入的分?jǐn)?shù)為“mark”,且分?jǐn)?shù)會有小數(shù)

  import java.util.Scanner;//頭文件

  class Mark{

  public static void main(String[] args){

  System.out.println("請輸入一個(gè)分?jǐn)?shù)");double mark;

  Scanner scanner = new Scanner(System.in);

  mark = scanner.nextDouble();

  2、判斷是否有輸入錯誤。

  if(mark<0||mark>100){

  System.out.println("輸入有誤! ");

  System.exit(0);

  }

  3、判斷分?jǐn)?shù)的等級

  90以上A, 80~89B,70~79分C,60~69D,60以下E

  if (mark>=90) System.out.println("this mark is grade 'A' ");

  else if (mark>=80) System.out.println("this mark is grade 'B' ");

  else if (mark>=70) System.out.println("this mark is grade 'C' ");

  else if (mark>=60) System.out.println("this mark is grade 'D' ");

  else  System.out.println("this mark is grade 'E' ");

  4、完整代碼

  import java.util.Scanner;

  class Mark{

  public static void main(String[] args){

  System.out.println("請輸入一個(gè)分?jǐn)?shù)");

  double mark;

  Scanner scanner = new Scanner(System.in);

  mark = scanner.nextDouble();

  if(mark<0||mark>100){

  System.out.println("輸入有誤! ");

  System.exit(0);

  }

  if (mark>=90) System.out.println("this mark is grade 'A' ");

  else if (mark>=80) System.out.println("this mark is grade 'B' ");

  else if (mark>=70) System.out.println("this mark is grade 'C' ");

  else if (mark>=60) System.out.println("this mark is grade 'D' ");

  else  System.out.println("this mark is grade 'E' ");

  }

  }


【JAVA中的if語句的使用】相關(guān)文章:

JAVA中If語句的使用02-22

Java for循環(huán)語句使用03-31

Java中synchronized的使用實(shí)例05-31

Java中shuffle算法的使用03-05

講解Java編程中finally語句的使用方法08-11

Java for循環(huán)語句使用實(shí)例01-13

關(guān)于Java for循環(huán)語句使用07-19

關(guān)于Java for循環(huán)語句的使用02-24

Java中break、continue、return語句的使用區(qū)別對比07-27