iT邦幫忙

2024 iThome 鐵人賽

DAY 19
0
Mobile Development

Kotlin and Java 開發 Android APP 學習系列 第 19

Java if/else 二選一敘述 條件運算式「? :」 9/20

  • 分享至 

  • xImage
  •  

請輸入0~100,來決定您是否及格。

Single if/else example

import java.util.Scanner;

public class If_Else {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("Please enter your score:");
		int score = sc.nextInt();
		sc.close();
		
		// 單一 if/else 條件敘述來判斷成績是否及格
		if (60<=score && score<=100) {
			System.out.print("Pass!!");
		}else {
			System.out.print("failed!!");
		}
	}
}

條件運算式

conditional expressions


上一篇
Java 9/19
下一篇
Java 物件導向程式設計(Object Oriented Programming, OOP)
系列文
Kotlin and Java 開發 Android APP 學習30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言