单项选择题

下列程序的输出结果是( )。 public class Test { public static void main (String[] args) { int n=5,sum=0; while (n>0) { sum+=n; --n; } System.out.println("Sum is"+sum); } }

A.sum is 14
B.sum is 15
C.sum is 10
D.sum is 5
<上一题 目录 下一题>
热门 试题

单项选择题
给出下面不完整的类代码,则横线处的语句应该为( )。 class Person { String name,department; int age; public Person (Strings) {name=s;} public Person (String s,int a) {name=s;age=a;} public Person (String n,String d,int a){ __________ department=d; } }
A.Person (n,;
B.this (Person(n,);
C.this(n,;
D.this(name,ag;
单项选择题
下面程序片段的执行中,说法正确的是( )。 public class Test { public static void main (String args[]) { byte y=20; int i=y; int x=100; y=x; System.out.println(y); } }
A.输出y的值为100
B.第4行错误
C.输出y的值为20
D.第6行错误
相关试题
  • 下列关于异常处理机制原则的说法中,错误的...
  • 下列能正确计算45°的余弦值的是( )。
  • 给出下面程序段 if(x>0) System.out...
  • 下列不属于Applet运行过程的是( )。
  • 下面程序代码运行结果为( )。 import ...