)。
public class Test {
int x, y;
Test(int x, int y) {
this.x = x;
this.y = y;
}
public static void main(String[] args) {
Test pt1, pt2;
pt1 = new Test(3, 3);
pt2 = new Test(4, 4);
System.out.print(pt1.x + pt2.x);
}
}
举一反三
- (6-6)请阅读程序,写出程序运行结果。 class Test{ static int x=10; int y=99; { y=y+10; } static { x=x+5; } { y=y+10; } static { x=x+5; } public Test() {//构造方法 x=x+5; } { System.out.println(x*y); } } public class Demo11 { public static void main(String[] args) { Test t1=new Test(); Test t2=new Test(); } }
- 以下是"public static void test(int x, int y)"的方法重载( ) A: public static void Test(int x) B: public static int test(int x, int y) C: public static void test(int y, int x) D: public static void test(int x, int y)
- 下列程序运行后的输出结果是:_____#includestdio.hvoid fun( int *pa, int pb ) { int pt; pt = *pa, *pa = pb, pb = pt;}int main( ){ int x=1, y=2; fun(x, y); printf(%d, x==y); return 0;}
- 请阅读下面的程序 public class Test { public static void main(String[] args) { int x; int y; for (x = 1, y = 1; x <= 100; x++) { if (y >= 20) { break; } if (y % 3 == 1) { y += 3; continue; } y -= 5; } System.out.println(“x=” + x + “,y=” + y); } } 下列选项中,哪一个是程序的运行结果( )
- 写出以下程序的运行结果。using System;class Test{public static void Main(){int x = 5;int y = x++;Console.WriteLine(y);//第1空y=++x;Console.WriteLine(y);//第2空}}
内容
- 0
class Test{int x;static int y;static void Main(){Test t = new Test();t.x = 1;t.y = 1;test.x = 1;test.y = 1;}}以上程序中共有几句错误() A: 1 B: 2 C: 3 D: 4
- 1
以下代码的输出是 :void swap( int *pa, int *pb ) { int pt; pt = *pa, *pa = *pb, *pb = *pa; } int main(void) { int x=1, y=2; swap(&x, &y); printf("%d%d", x, y); }
- 2
以下代码的输出是 :void f( int *pa, int *pb ) { int pt; pt = *pa, *pa = *pb, *pb = *pa; } int main(void) { int x=1, y=2; f(&x, &y); printf("%d%d", x, y); }
- 3
using System; class Test { public static void Main() { int x = 5; int y = x++; Console.WriteLine(y); y=++x; Console.WriteLine(y); } }
- 4
下面程序的输出为( )。 public class Test { public static void main (String args[]) { int x,y; x=1; y=2; System.out.println("The output is"+x+y); } } A: The output is xy B: The output is 3 C: The output is 12 D: The output is x=1 y=2