※J.Y Chen 的個人部落格 ※

Just Follow Our Heart And We will shine!

49 瀏覽人次

【程式語言】JAVA的期中上機測驗 |TEST 1 輸入名字並輸出歡迎詞

Published: in JAVA by .

import java.util.Scanner;
public class test_1 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.print("Please input your name:");
		String name = input.next();
		System.out.println("Hello," + name);
		
		System.out.print("input a number a:");
		int num_a = input.nextInt();
		System.out.print("input a number b:");
		int num_b = input.nextInt();
		if (num_a > num_b) {
			System.out.println(num_a + " is the bigger number and " + num_b + "is the smaller number!");
			System.out.println(num_a + "-" + num_b + "=" + (num_a - num_b));
		}else {
			System.out.println(num_b + " is the bigger number and " + num_a + "is the smaller number!");
			System.out.println(num_b + "-" + num_a + "=" + (num_a - num_b));
		}
	} 
	
}

Result:

©2019 - 2024 Henry Chen