单选题import java.io.PrintWriter;  class DoFormat {  public static void main(String [] args) { int x = 42; int y = 12345;  float z = 7; System.out.format("-%4d- ", x);  System.out.format("-%4d- ", y);  System.out.format("-%4.1d- ", z); } }  结果为:()A 编译失败B -42

题目
单选题
import java.io.PrintWriter;  class DoFormat {  public static void main(String [] args) { int x = 42; int y = 12345;  float z = 7; System.out.format("-%4d- ", x);  System.out.format("-%4d- ", y);  System.out.format("-%4.1d- ", z); } }  结果为:()
A

编译失败

B

-42- -1234- -7.0-

C

- 42- -1234- - 7.0-

D

运行时异常被抛出


相似考题
更多“单选题import java.io.PrintWriter;  class DoFormat {  public static void main(String [] args) { int x = 42; int y = 12345;  float z = 7; System.out.format("-%4d- ", x);  System.out.format("-%4d- ", y);  System.out.format("-%4.1d- ", z); } }  结果为:()A 编译失败B -42”相关问题
  • 第1题:

    下面程序段的输出结果为 package test; public class A { int x=20; static int y=6; public static void main(String args[]) { Class B b=new Class B(); b.go(10); System.out.println(”x=”+b.x); } } class Class B { int x; void go(int y) { ClassA a=new ClassA(); x=a.y; } }

    A.x=10

    B.x=20

    C.x=6

    D.编译不通过


    正确答案:C
    解析:本题考查在Java中静态变量(类变量)的用法。在题目程序段中生成了一个staticinty=6类变量,在ClassA中调用的b.go(10),只不过是在ClassB中的一个局部变量,通过调用ClassB中的go方法可以生成一个ClassA对象,并给这个新生成的对象赋以ClassA中的类变量y的值。从main()方法作为入口执行程序,首先生成一个ClassB的对象,然后b.go(10)会调用ClassA,会给x和y赋值,x=a.y后,x值为6,再返回去执行System.out.println(”x=”+b.x)语句,输出为x=6,可见,正确答案为选项C。

  • 第2题:

    以下程序的输出结果为:public class test {public static void main(String args[]) {int x=1,y=1,z=1;if (x--==1&&y++==1||z++== 1、System.out.println("x="+x+",y="+y+",z="+z);}}

    A. x=0,y=2,z=1

    B. x=1,y=2,z=1

    C. x=0,y=1,z=1

    D. x=0,y=2,z=2


    正确答案:A

  • 第3题:

    现有:  class  Test4  {  public static void main (String  []  args)  {    boolean X=true;   boolean y=false;    short Z=42;    if((z++==42)  &&  (y=true))z++;    if((x=false)  ||    (++z==45))  z++;    System. out.println(¨z=”+z);     }    }  结果为:() 

    • A、  Z=42
    • B、  z=44
    • C、  Z= 45
    • D、  z= 46

    正确答案:D

  • 第4题:

    现有:  class Foo  {  public static void main (String  []  args)  {      int x=O;      int y=4;  for (int  z=0;  z<3;  Z++;  X++)  {     if(x>1&++y<10)    y++;    }  System. out .println (y);  }   }  结果是什么?()     

    • A、7
    • B、8
    • C、10
    • D、12

    正确答案:B

  • 第5题:

    class Top {  static int x = 1;  public Top(int y) { x *= 3; }  }  class Middle extends Top {  public Middle() { x += 1; }  public static void main(String [] args) {  Middle m = new Middle();  System.out.println(x);  }  }  结果为:() 

    • A、1
    • B、2
    • C、3
    • D、编译失败

    正确答案:D

  • 第6题:

    class TestMain {   static int x = 2;   static { x = 4; }   static public void main(String[] args) {   int y = x + 1;   System.out.println(y);  }  }   和命令行:   java TestMain   结果为:()

    • A、 3
    • B、 5
    • C、 编译失败
    • D、 运行时异常被抛出

    正确答案:B

  • 第7题:

    class Test4 {   public static void main(String [] args) {   boolean x = true;   boolean y = false;   short z = 42;   if((z++ = = 42) && (y = true)) z++;   if((x = false) || (++z = = 45)) z++;   System.out.println("z = " + z);   }   }   结果为:()  

    • A、z = 42
    • B、z = 44
    • C、z = 45
    • D、z = 46

    正确答案:D

  • 第8题:

    单选题
    现有:   class TestMain {       static int x = 2;    static { x = 4; }   public static void main(String... args) {     int y = x + 1;   System.out.println(y);   }   }    和命令行:  java TestMain    结果为:()
    A

     3

    B

     5

    C

     编译失败

    D

     运行时异常被抛出


    正确答案: A
    解析: 暂无解析

  • 第9题:

    单选题
    现有:   class TestMain {      static int x = 2;  static { x = 4; }   static public void main(String[] args) {    int y = x + 1;   System.out.println(y);    }    }    和命令行:  java TestMain    结果为:()
    A

     3

    B

     5

    C

     编译失败

    D

     运行时异常被抛出


    正确答案: B
    解析: 暂无解析

  • 第10题:

    单选题
    class Test2{   public static void main(String [] args){   boolean x=true;   boolean y=false;   short z=42;   if((x==true)&&y=true))z++;   if((y==true||++z=44))z++;   System.out.println(“z=”+z);  }  }   结果是什么?()
    A

     z=42

    B

     z=43

    C

    z=44

    D

     z=45

    E

    编译失败

    F

    运行的时候有异常抛出


    正确答案: A
    解析: 暂无解析

  • 第11题:

    单选题
    class Foo {  public static void main(String [] args) {  int x = 0;  int y = 4;  for(int z=0; z 〈 3; z++, x++) {  if(x 〉 1 & ++y 〈 10) y++;  }  System.out.println(y);  }  }  结果是什么?()
    A

    6

    B

    7

    C

    8

    D

    10


    正确答案: B
    解析: 暂无解析

  • 第12题:

    单选题
    class Top {  static int x = 1;  public Top(int y) { x *= 3; }  }  class Middle extends Top {  public Middle() { x += 1; }  public static void main(String [] args) {  Middle m = new Middle();  System.out.println(x);  }  }  结果为:()
    A

    1

    B

    2

    C

    3

    D

    编译失败


    正确答案: B
    解析: 暂无解析

  • 第13题:

    下面程序段的输出结果为 package test; public class Class A { int x=20; static int y=6; public static void main(String args[]) { Class B b=new Class B(); b.go(10); System.out.println("x"+b.x); } } class ClassB { int x; void go(int y) { ClassA a=new ClassA(); x=a.y; } }

    A.x=10

    B.x-20

    C.x=6

    D.编译不通过


    正确答案:C
    解析:本题考查在Java中静态变量(类变量)的用法。在题目程序段中生成了一个staticinty=6类变量,在ClassA中调用的b.go(10),只不过是在ClassB中的一个局部变量,通过调用ClassB中的go方法可以生成一个ClassA对象,并给这个新生成的对象赋以ClassA中的类变量y的值。从main()方法作为入口执行程序,首先生成一个ClassB的对象,然后b.go(10)会调用ClassA,会给x和y赋值,x=a.y后,x值为6,再返回去执行System.out.println("x="+b.x)语句,输出为x=6,可见,正确答案为逸项C。

  • 第14题:

    现有  import java.io.PrintWriter;      class  DoFormat{  public  static void main (String  []  args)  {      int x=42;  int y=12345;     float Z-7 ;  System.out.format("一%4d-",  X); System. out.format("-%4d-",  y);     System. out.format("-%4.ld-",z);      }      }      结果为:()     

    • A、编译失败
    • B、  -42-  -1234- -7.0-
    • C、 - 42- -1234- -7.0-
    • D、 - 42- -12345- -7.0-
    • E、运行时异常被抛出

    正确答案:E

  • 第15题:

    class Foo {  public static void main(String [] args) {  int x = 0;  int y = 4;  for(int z=0; z 〈 3; z++, x++) {  if(x 〉 1 & ++y 〈 10) y++;  }  System.out.println(y);  }  }  结果是什么?()  

    • A、6
    • B、7
    • C、8
    • D、10

    正确答案:C

  • 第16题:

    现有:  class TestMain {   static int x = 2;   static { x = 4; }   public static void main(String... args) {   int y = x + 1;   System.out.println(y);   }   }   和命令行:   java TestMain   结果为:()  

    • A、 3
    • B、 5
    • C、 编译失败
    • D、 运行时异常被抛出

    正确答案:B

  • 第17题:

    public class MethodOver {   private int x, y;   private float z;   public void setVar(int a, int b, float c){   x = a;   y = b;   z = c;   }   }   Which two overload the setVar method?()

    • A、 void setVar (int a, int b, float c){  x = a;  y = b;  z = c;  }
    • B、 public void setVar(int a, float c, int b) {  setVar(a, b, c);  }
    • C、 public void setVar(int a, float c, int b) {  this(a, b, c);  }
    • D、 public void setVar(int a, float b){  x = a;  z = b;  }
    • E、 public void setVar(int ax, int by, float cz) {  x = ax;  y = by;  z = cz;  }

    正确答案:B,D

  • 第18题:

    class Test2{   public static void main(String [] args){   boolean x=true;   boolean y=false;   short z=42;   if((x==true)&&y=true))z++;   if((y==true||++z=44))z++;   System.out.println(“z=”+z);  }  }   结果是什么?()  

    • A、 z=42
    • B、 z=43
    • C、z=44
    • D、 z=45
    • E、编译失败
    • F、运行的时候有异常抛出

    正确答案:D

  • 第19题:

    import java.io.PrintWriter;  class DoFormat {  public static void main(String [] args) { int x = 42; int y = 12345;  float z = 7; System.out.format("-%4d- ", x);  System.out.format("-%4d- ", y);  System.out.format("-%4.1d- ", z); } }  结果为:() 

    • A、编译失败
    • B、-42- -1234- -7.0-
    • C、- 42- -1234- - 7.0-
    • D、运行时异常被抛出

    正确答案:D

  • 第20题:

    单选题
    现有:  class  Test4  {  public static void main (String  []  args)  {    boolean X=true;   boolean y=false;    short Z=42;    if((z++==42)  &&  (y=true))z++;    if((x=false)  ||    (++z==45))  z++;    System. out.println(¨z=”+z);     }    }  结果为:()
    A

      Z=42

    B

      z=44

    C

      Z= 45

    D

      z= 46


    正确答案: A
    解析: 暂无解析

  • 第21题:

    单选题
    现有  import java.io.PrintWriter;      class  DoFormat{  public  static void main (String  []  args)  {      int x=42;  int y=12345;     float Z-7 ;  System.out.format("一%4d-",  X); System. out.format("-%4d-",  y);     System. out.format("-%4.ld-",z);      }      }      结果为:()
    A

    编译失败

    B

      -42-  -1234- -7.0-

    C

     - 42- -1234- -7.0-

    D

     - 42- -12345- -7.0-

    E

    运行时异常被抛出


    正确答案: A
    解析: 暂无解析

  • 第22题:

    单选题
    class Test4 {   public static void main(String [] args) {   boolean x = true;   boolean y = false;   short z = 42;   if((z++ = = 42) && (y = true)) z++;   if((x = false) || (++z = = 45)) z++;   System.out.println("z = " + z);   }   }   结果为:()
    A

    z = 42

    B

    z = 44

    C

    z = 45

    D

    z = 46


    正确答案: B
    解析: 暂无解析

  • 第23题:

    单选题
    现有:  class Foo  {  public static void main (String  []  args)  {      int x=O;      int y=4;  for (int  z=0;  z1&++y<10)    y++;    }  System. out .println (y);  }   }  结果是什么?()
    A

    7

    B

    8

    C

    10

    D

    12


    正确答案: A
    解析: 暂无解析