欧美日韩不卡一区二区三区,www.蜜臀.com,高清国产一区二区三区四区五区,欧美日韩三级视频,欧美性综合,精品国产91久久久久久,99a精品视频在线观看

java語言

JAVA中的if語句的使用

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

JAVA中的if語句的使用

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

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

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

  class Mark{

  public static void main(String[] args){

  System.out.println("請輸入一個分數");double mark;

  Scanner scanner = new Scanner(System.in);

  mark = scanner.nextDouble();

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

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

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

  System.exit(0);

  }

  3、判斷分數的等級

  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("請輸入一個分數");

  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語句的使用】相關文章:

JAVA中If語句的使用02-22

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

Java中synchronized的使用實例05-31

Java中shuffle算法的使用03-05

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

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

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

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

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