niusouti.com

下面是关于字符界面基本输入输出的程序,请在程序的每条横线处填写一个语句,使程序的功能完整。注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。______________________public class SimpleCharInOut{public static void main(String args[]){char c=" ";System.out.println("Enter a character please: ");try{________________

题目

下面是关于字符界面基本输入输出的程序,请在程序的每条横线处填写一个语句,使程序的功能完整。

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

______________________

public class SimpleCharInOut{

public static void main(String args[]){

char c=" ";

System.out.println("Enter a character please: ");

try{

____________________//接受用户键盘输入的字符并保存在变量c中

}

catch(________________________e){}

System.out.println("You've entered character "+c);

}

}


相似考题
参考答案和解析
正确答案:import java.io.*; c=(char)System.in.read(); IOException或Exception
import java.io.*; c=(char)System.in.read(); IOException或Exception 解析:本题主要考查try-catch异常捕获结构。解答本题的关键是熟练掌握异常的捕获知识。在本题中,import java.io.*;语句的功能是导入java.io包,c=(char)System.in.read();语句的功能是从键盘缓冲区获得一个字符数据,并赋给字符变量C,IOExcepfion e声明一个IOExcepfion型对象e。
更多“下面是关于字符界面基本输入输出的程序,请在程序的每条横线处填写一个语句,使程序的功能完整。 注 ”相关问题
  • 第1题:

    创建线程对象,要传递代码与数据,而传递代码与数据有两种方法,一是通过继承Thread类,二是向Thread类传递一个Runnable对象。请在下面程序的每条横线处填写一个语句,使程序的功能完整。

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

    public class TestThread{

    public static void main(String args[ ])

    {

    MyThread t=new MyThread();

    _______________________

    }

    }

    class MyThread_____________Thread{

    _____________________

    {

    for(int i=0;i<10;i++){

    System.out.println(" " +i);

    }

    }

    }


    正确答案:t.start(); extends public void run();
    t.start(); extends public void run(); 解析: 本题主要考查创建线程的方法、线程的执行过程。解答本题的关键是熟练掌握创建线程的方法、执行过程。在本题中, t.start();语句的功能是启动线程t,使其处于可运行状态,classMyThreadextendsThread中的extends的作用是使Mythread线程为线程Thread的直接子类,public void run()的功能是重载run()方法。

  • 第2题:

    下面的程序是用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。

  • 第3题:

    下面的程序是求字符串的长度及每一个位置上的字符。请在每条横线处填写一条语句,使程序的功能完整。

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

    public class CharAtOp{

    public static void main(String args[ ]){

    String str="abcdef";

    int size=

    System.out.println("字符串str的长度为: "+size);

    for(int m=0;___________________m++)

    {

    _______________________

    System.out.println("str中的第"+m+"个字符是: "+c);

    }

    }

    }


    正确答案:str.length(); msize; char c=str.charAt(m);
    str.length(); msize; char c=str.charAt(m); 解析:本题主要考查对String数据的操作的基本知识、for循环语句的基本知识。解答本题的关键是熟练掌握对String数据的操作的基本知识、for循环语句的基本知识。在本题中,int size=str,length();语句的功能是获得字符串对象str的长度,for(int m=0;msize;m++)语句中的msize;是for循环语句的判断部分,charc=str,charAt(m);语句的功能是获得字符串中指定位置的字符。

  • 第4题:

    下面的程序的功能是简单的进行键盘输入测试,请在程序的每条横线处填写一个语句,使程序的功能完整。

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

    ____________________

    public class TestKeyBoardInPut

    {public static void main(String[] args)

    {String yourname=JOptionPane. ____________________ ("What is your name?");

    System.out.println("Hello"+yourname);

    ____________________.exit(0);

    }

    }


    正确答案:import javax.swing.*; showInputDialog System
    import javax.swing.*; showInputDialog System 解析:本题主要考查javax.swing包、showInputDialog()方法。解答的关键是掌握javax.swing包、showInputDialog()方法。在本题中,import javax.swing.*;语句的功能是导入javax.swing包,String yourname=JOptionPane.showInputDialog("What is your name?");语句的功能是从控制台键盘读入字符串并赋值yourname,System.exit(0);语句的功能是退出Java的运行环境回到操作系统环境下。

  • 第5题:

    下面的程序的功能是求1~100的奇数的和及该和的平均值。请在程序的每条横线处填写一个语句,使程序的功能完整。

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

    public class SumAndAve{

    public static void main(String args[]){

    int count = 0, sum = 0, ave= 0;

    for (int i = 1; i<= 100; ______)

    if(______)

    continue;

    else

    {

    ______

    sum=sum+i;

    }

    ave= sum/count;

    System.out.println( "sum="+sum);

    System.out.println( "ave="+ave);

    }

    }


    正确答案:i+=2 i%2==0 ++count;
    i+=2 i%2==0 ++count; 解析:本题主要考查for循环语句的用法。在本题中,for(int i=1;i=100;i+=2;)语句是用来控制被求的奇数,i+=2;语句是使循环变量递增2,即所求的奇数,如果该数不为奇数,即if (i%2==0),continue,跳过循环体余下的语句,对for语句的“表达式3”即i+=2求值;如果该数为奇数,用count计数器记录所求奇数的个数。