1. 输出"Hello World!" 不包含双引号(")
public class Main {
public static void main(String args[]){
System.out.println("Hello World!");
}
}
2.
京大学计算中心的英文缩写是PKUCC,下面是用ASCII ART输出的图形,请写一段代码输出它。
######## ## ## ## ## ###### ######
## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ##
######## ##### ## ## ## ##
## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ##
## ## ## ####### ###### ######
public class Main { public static void main(String[] args) { System.out.println("######## ## ## ## ## ###### ######"); System.out.println("## ## ## ## ## ## ## ## ## ##"); System.out.println("## ## ## ## ## ## ## ##"); System.out.println("######## ##### ## ## ## ##"); System.out.println("## ## ## ## ## ## ##"); System.out.println("## ## ## ## ## ## ## ## ##"); System.out.println("## ## ## ####### ###### ######"); } }
3.题目描述:
计算 a + b 的值
输入:
两个整数 a,b (0 ≤ a,b ≤ 10)
输出:
计算 a + b 的结果
在老师网站能通过编译的:
import java.io.*;
import java.util.*;
public class Main {
public static void main(String args[]) throws Exception {
Scanner cin=new Scanner(System.in);
int a=cin.nextInt(),b=cin.nextInt();
System.out.println(a+b);
}
}
自己做的:
import java.util.InputMismatchException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sin = new Scanner(System.in);
int first = 0, second = 0;
try {
System.out.print("请输入第一个>=0的整数:");
first = sin.nextInt();
System.out.print("请输入第二个<=10的整数:");
second = sin.nextInt();
if (first < 0 || second > 10) {
System.out.println("数据输入错误!");
} else {
System.out.println(first + "+" + second + "=" + (first + second));
}
} catch (InputMismatchException e) {
System.out.println("错误!请输入整数");
}
}
}