题目1
public void function1() {
int x = 10;
int y = x++ + 5;
System.out.println("x=" + x + "------y=" + y);
int m = 10;
int n = ++m + 5;
System.out.println("m=" + m + "------n=" + n);
int a = 10;
int b = ++a + ++a;
System.out.println("a=" + a + "------b=" + b);
int c = 10;
int d = ++c + c++;
System.out.println("c=" + c + "------d=" + d);
int g = 10;
int h = g++ + ++g;
System.out.println("g=" + g + "------h=" + h);
int e = 10;
int f = e++ + e++;
// int f = e++ + 0 + e++;
System.out.println("e=" + e + "------f=" + f);
}
题目2
public void function2() {
int r = 0;
int result = ++r + r++ + ++r + r;
//result的值为多少
System.out.println("result=" + result + "----r=" + r);
}
题目3
public void function3() {
int i1 = 20, i2 = 5;
System.out.println("i1 + i2 = " + i1 + i2);
System.out.println("i1 - i2 = " + (i1 - i2));
// System.out.println("i1 - i2 = " + i1 - i2); //语法报错,连编译都通不过
System.out.println("i1 * i2 = " + i1 * i2);
System.out.println("i1 / i2 = " + i1 / i2);
}
题目4
//java规定,月份从0到11
public void function4() {
Calendar c = Calendar.getInstance();
System.out.println(c.get(Calendar.YEAR));
System.out.println(c.get(Calendar.MONTH));
System.out.println(c.get(Calendar.DAY_OF_MONTH));
//不要用Date()里面的 getMonth(),getDate()等方法,因为sun已经不提倡使用这些方法了,随时可能在以后的版本里取消
Date date = new Date();
System.out.println(date.getMonth() + "-" + date.getDate());
}
其实今天是2019年9月24日,但是运行结果是8月,因为java规定,月是从0到11
题目5
public void testFunction(String str) {
System.out.println("String");
}
public void testFunction(Object obj) {
System.out.println("Object");
}
public static void main(String[] args) {
Test test = new Test();
test.testFunction(null);
test.testFunction(new Test());
test.testFunction("江西省赣州市于都县");
test.function1();
test.function2();
test.function3();
test.function4();
}
源代码如下
package javase3;
import java.util.Calendar;
import java.util.Date;
//java笔试题
public class Test {
public void testFunction(String str) {
System.out.println("String");
}
public void testFunction(Object obj) {
System.out.println("Object");
}
public static void main(String[] args) {
Test test = new Test();
test.testFunction(null);
test.testFunction(new Test());
test.testFunction("江西省赣州市于都县");
test.function1();
test.function2();
test.function3();
test.function4();
}
public void function1() {
int x = 10;
int y = x++ + 5;
System.out.println("x=" + x + "------y=" + y);
int m = 10;
int n = ++m + 5;
System.out.println("m=" + m + "------n=" + n);
int a = 10;
int b = ++a + ++a;
System.out.println("a=" + a + "------b=" + b);
int c = 10;
int d = ++c + c++;
System.out.println("c=" + c + "------d=" + d);
int g = 10;
int h = g++ + ++g;
System.out.println("g=" + g + "------h=" + h);
int e = 10;
int f = e++ + e++;
// int f = e++ + 0 + e++;
System.out.println("e=" + e + "------f=" + f);
}
public void function2() {
int r = 0;
int result = ++r + r++ + ++r + r;
//result的值为多少
System.out.println("result=" + result + "----r=" + r);
}
public void function3() {
int i1 = 20, i2 = 5;
System.out.println("i1 + i2 = " + i1 + i2);
System.out.println("i1 - i2 = " + (i1 - i2));
// System.out.println("i1 - i2 = " + i1 - i2); //语法报错,连编译都通不过
System.out.println("i1 * i2 = " + i1 * i2);
System.out.println("i1 / i2 = " + i1 / i2);
}
//java规定,月份从0到11
public void function4() {
Calendar c = Calendar.getInstance();
System.out.println(c.get(Calendar.YEAR));
System.out.println(c.get(Calendar.MONTH));
System.out.println(c.get(Calendar.DAY_OF_MONTH));
//不要用Date()里面的 getMonth(),getDate()等方法,因为sun已经不提倡使用这些方法了,随时可能在以后的版本里取消
Date date = new Date();
System.out.println(date.getMonth() + "-" + date.getDate());
}
}
运行结果如下