【程式語言】JAVA的期中上機測驗 |TEST 1 輸入名字並輸出歡迎詞
Published:
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));
}
}
}