以下代码运行后输出的内容( )public class Main { public static double div(int a, int b) { return (double)a/b; } public static int div(int a, int b) { return a/b; } public static void main(String[] args) { System.out.println(div(5, 2)); } }
A: 2.5
B: 2
C: 输出内容不确定
D: 程序错误,无法运行
A: 2.5
B: 2
C: 输出内容不确定
D: 程序错误,无法运行
举一反三
- public class test1 { public static int add(int a, int b) { return a+b; } public static double add(double a, double b) { return a+b; } ________________ ___________________ { ________________ ___________________ } public static void main(String[] args) { System.out.println("调用add方法:"+add(2.1,3.4,4.5)); } }
- class Demo{ public static void main(String[] args){ int x = 0; try{ x = div(1,2); }catch(Exception e){ System.out.println(e); } System.out.println(x) ; } public static int div(int a,int b){ return a / b ; } }
- 中国大学MOOC: public class Test{ public static void main(String[ ] args) { int result =???; System.out.println(result); } public static int operate(double a, int b) { return 10*(int)(a+b); } public static int operate(int a, double b) { return 100*(int)(a+b); } public static int operate(double a, double b) { return 1000*(int)(a+b); }}???处填入( )时,编译程序会出错。
- 写出程序的运行结果。 public class Demo{ public static void main(String args[]) { int b = get(); System.out.println(b); } public static int get() { try { return 1; } finally { return 2; } } }
- 下面程序的运行结果( )public class Demo{public static int fun(int c){return c+=2;}public static void main(String[] args){int temp=fun(2);System.out.println(temp);}} A: 2 B: 4 C: 6 D: 8