niusouti.com

请完成下列Java程序。程序的输出结果:a=6,b=5。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。程序运行结果如下:public class ex38_2{public static void main(String args[]){int a=5,b=6;a=_________;b=a-b;a=_________;System.out.println("a="+a+"\tb="+b);}}

题目

请完成下列Java程序。程序的输出结果:a=6,b=5。

注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。

程序运行结果如下:

public class ex38_2{

public static void main(String args[])

{

int a=5,b=6;

a=_________;

b=a-b;

a=_________;

System.out.println("a="+a+"\tb="+b);

}

}


相似考题
更多“ 请完成下列Java程序。程序的输出结果:a=6,b=5。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。程序运行结果如下:public class ex38_2{public st”相关问题
  • 第1题:

    下面程序执行后,输出结果为:true请在程序的每条横线处填写一个语句,使程序的功能完整。

    注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。

    public class TestStringCompare{

    {public static void main(String ____________________ args)

    {char charl[]={'t','e','s','t'};

    char char2[]={'t','e','s','t','1'};

    String str1=new String(___________________);

    String str2=new String(char2,0,4);

    System.out.println(__________________________);

    }

    }


    正确答案:[ ] char1 str1.equals(str2)
    [ ] char1 str1.equals(str2) 解析:本题主要考查main()主方法的使用、String类的使用。解答本题的关键是熟练掌握main()主方法的使用、String类的使用。在本题中,public static void main(String[]args)中的[]是定义数组的标志,str1.equals(str2)语句的功能是判断字符串str1和字符串str2的内容是否相等。

  • 第2题:

    请完成下列Java程序。实例listener是监听器,frm是事件源,fr上发生的事件委托tat进行处理。程序的执行结果是显示一个蓝色的窗口,单击关闭按钮,可关闭窗口。

    注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。

    源程序文件代码清单如下:

    import java.awt.*;

    import java.awt.event.*;

    public class BlueWindow

    {

    public static void main(String args[])

    {

    Frame. frm=new Frame. ("欢迎参加Java考试!");

    TheAdapterTest listener=new TheAdapterTest();

    frm. ______;

    frm.setSize(200,200);

    frm.setBackground(Color.blue);

    frm. ______;

    }

    }

    class TheAdapterTest extends WindowAdapter

    {

    public void windowClosing(WindowEvent e)

    {

    System.exit(1);

    }

    }


    正确答案:addWindowListener(listener) setVisible(true)
    addWindowListener(listener) setVisible(true) 解析:本题主要考查窗体事件的处理机制。解答本题的关键是熟悉Java语言的事件处理机制(事件、事件源和事件处理者)。在本题中,frm.addWindowListener(listener);语句的功能是为窗体对象注册监听器;frm.setVisible (true)语句的功能是使生成的窗体具有可见性,若frm.setVisible(false),则生成的窗体是不可见的。

  • 第3题:

    请完成下列Java程序:实现打印出自己的源文件的功能。

    注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。

    import java.io.*;

    import java.util.StringTokenizer;

    public class ex27_2{

    public static void main(String args[])throws IOException{

    FileInputStream fis=new FileInputStream("ex27_2.java");

    DataInputStream dis=new DataInputStream(fis);

    String str=null;

    while(true){

    __________________;

    if(str==null){

    __________________;

    }

    StringTokenizer st=new StringTokenizer(str);

    while(st.hasMoreTokens()){

    System.out.print(st.nextToken()+ " " );

    }

    System.out.println();

    }

    }

    }


    正确答案:str=dis.readLine() break
    str=dis.readLine() break 解析:本题主要考查文件I/O操作和while语句,if语句的使用。解题关键是熟悉文件I/O操作的基本方法,以及利用while语句和if语句控制程序流程。本题中,第1个空,DataInputStream的对象dis调用readLine()方法,从输入流中读取数据,并写给String类的str对象;第二空,如果str为空,则跳出循环体,这里使用break完成跳转。

  • 第4题:

    下面程序是关于类的继承的用法。阅读下面程序,根据程序中的注释在每一条横线处填写一个语句,使程序的功能完整,且运行程序后的输出结果为:

    I am parentclass!

    I am childclass!

    I am childclass!

    注意: 请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。

    class Parent {

    void printMe() {

    System.out.println("I am parentclass!");

    }

    }

    class Child extends Parent {

    void printMe() {

    System.out.println("I am childclass!");

    }

    void printAll() {

    ______________.printMe ( ); // 调用父类的方法

    ______________. printMe ( ); //调用本类的方法

    printMe ( );

    }

    }

    public class TestJieCheng {

    public static void main(String args[]) {

    ______________

    myC.printAll();

    }

    }


    正确答案:super this Child myC=new Child();
    super this Child myC=new Child(); 解析:本题主要考查super,this关键字以及如何生成对象。解答本题的关键是熟练super,this的用法、对象的生成。在本题中, super.printMe();语句的功能是调用父类的printMe()方法,this.printMe();语句的功能是调用本类的printMe()方法,Child myC=new Child();语句的功能是生成Child类的对象myC。

  • 第5题:

    下面的程序是用do_while语句计算10的阶乘。请在程序的每条横线处填写一个语句,使程序的功能完整。

    注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。

    源程序文件代码清单如下:

    public class DoWhileLoop

    {

    public static void main(________)

    {

    int n=10;

    long result=1;

    do

    {

    _______________

    }

    ______________

    System.out.println("10的阶乘为: "+result);

    }

    }


    正确答案:String args[] result*=n--; while(n>=1);
    String args[] result*=n--; while(n>=1); 解析:本题主要考查main()主方法的使用、while循环语句的用法。解答本题的关键是熟练掌握 main()土方法的使用、while循环语句的用法。在本题中,String args[]的作用是声明字符数组args, result*=n--;语句的作用是获得n的阶乘并赋值给变量result。