题目详情
当前位置:首页 > 计算机考试 > 初级程序员
题目详情:
发布时间:2023-12-12 07:16:11

[简答题]【说明】
下面程序完成从键盘读入一个字符串,然后采用parseInt方法将其转换为一个相应的整数。
import java.io.*;
public class testThrows
public static (1) readString( ) (2) IOException
int ch;
String r="";
boolean done=false;
while( (3) )
ch=System.in.read( );
if(ch<0 || ch=0xd) //处理回车符中第一个符号
done=true;
else
r=r+(char)ch;

return r;

public static void main(Stling args[])
String str;
(4)
str=readString( );
(5) (IOException e)
System.out.println("error");
return;

System.out.println("input integer: "+Integer.parselnt(str));


更多"【说明】 下面程序完成从键盘读入一个字符串,然后采用parseInt"的相关试题:

[简答题]【说明】 下面程序完成从键盘读入一个字符串,然后采用parseInt方法将其转换为一个相应的整数。 import java.io.*; public class testThrows{ public static (1) readString( ) (2) IOException{ int ch; String r=""; boolean done=false; while( (3) ){ ch=System.in.read( ); if(ch<0 || ch=0xd) //处理回车符中第一个符号 done=true; else r=r+(char)ch; } return r; } public static void main(Stling args[]){ String str; (4) { str=readString( ); } (5) (IOException e){ System.out.println("error"); return; } System.out.println("input integer: "+Integer.parselnt(str)); } }
[填空题][说明]
下面Application程序用while循环从键盘读入字符,记录输入的字符数并输出读入的字符,当输入字符“0”时结束while循环,同时结束程序。
[Java程序]
import java.io.*;
public class ContinuateInput
public (1) void main(String[] args) (2) IOException
int ch;
int counter=0;
System.out .println("请输入字符(输入0结束)");
while ((char) (ch=System.in. (3) ) != ’0’)
counter++;
System.out .println (( (4) )ch) ;

System.out .println ( ) ;
System.out.println ("counted "+counter+" total bytes. ") ;
System.out . (5) ;



[简答题]下面给出了一个SHELL程序,试对其行后有#(n)形式的语句进行解释,并说明程序完成的功能。
#!/bin/bash
#(1)
dir=$1
#(2)
if [ -d $dir ]
#(3)
then
cd $dir
#(4)
for file in *
do
if [-f $file ]
#(5)
then
cat $file
#(6)
echo “end of file $file”
fi
done
else
echo “bad directory name $dir”
fi
[简答题][函数2.1说明] 下面程序的功能是:将由键盘输入的某个十进制数转换成对应的R进制数并输出。这里R是 2到16的整数,由键盘输入。例如,输入n=128,base=13后的输出为9B。 [函数2.1] #include <stdio.h> main( ) { char b[16]={’0’,’1’,’2’,’3’,’4’,’5’,’6’,’7’,’8’,’9’,’A’,’B’,’C’,’D’,’E’,’F’}; int c[64],n,i=0,base; printf("Enter a number:");scaaf("%d",&n); printf("Enter new base:");scanf("%d",&base); do{c[i]= (1) ; i++; n=n/base; }while( (2) ); printf("Transmit new base:"); for(- -i;i>=0;- -i)printf("%c", (3) ); } [函数2.2说明] 所谓回文字符中是指正序和逆序拼写相同的字符串,例如astrtsa,adgdtdgda等。下面函数int fun(char *str)的功能是判断字符串str是否是回文,当字符串是回文时,函数返回1,否则返回0。 [函数2.2] int fun(char *str) { int i,j,l; for(i=0;str[i]! =’/0’;i++); l=i/2; for(j=0,i- -;j<=1; (4) ) if( (5) ) return 0; return 1; }
[填空题]下面程序由终端键盘输入一个文件名。然后把从终端键盘输入的字符依次存放到该文件中,用#作为结束输入的标志。
#include<stdio.h>
#include
main( )
{FILE *fp;
char ch,fname[10];
printf("Please input the file name./n");
gets(fname);
if((fp=______)==NULL)/*第一空*/
{printf("( )pen it error/n");______;}/*第二空*/
else(printf("Enter the content/n");
while((ch=getchar( ))!=’#’)
______;/*第三空*/
}
fclose(fp);
}
[单项选择]若运行以下程序时,从键盘输入ADescriptor<回车>,则下面程序的运行结果是 ( ) 。
#include<stdio.h>
main( )
char c;
int v0=1,v1=0,v2=0;
do switch(c=getehar( ))
case’a’: case’A’:
case’e’:case’E’:
case’i’:case’I’:
case’o’:case’O’:
case’u’:case’U’:v1+=1
default:v0+=1;v2+=1;

while(c! =’/n’);
printf("v0=%d,v1=%d,v2=%d/n",v0,v1,v2);

A. v0=7,v1=4,v2=7
B. v0=8,v1=4,v2=8
C. v0=11,v1=4,v2=11
D. v0=13,v1=4,v2=12
[单项选择]若运行以下程序时,从键盘输入ADescriptor (<CR>表示回车) ,则下面程序的运行结果是( )。
#include <stdio.h>
main( )
char c;
int v0=1, v1=0, v2=0;
do(switch(c=getchar( ))
(case'a':case'A':
case 'e':case 'E':
case 'i':case 'T':
case 'o':case '0':
case 'u':case'U':v1+=1;
default:v0+=1; v2+=1; ) while(e!='/n');
printf("v0=%d, v1=%d, v2=%d/n", v0, v1, v2); )
A. v0=7, v1=4, v2=7
B. v0=8, v1=4, v2=8
C. v0=11, v1=4, v2=11
D. v0=13, v1=4, v2=12
[填空题]阅读以下说明和Java程序,将应填入 (n) 处的字句写在对应栏内。 [说明] 下面程序是为汽车市场编制的一个程序的一部分。其中automobile是基类。 [Java程序] class MainJava{ public static void main(String agr[]){ car sedan=new car( ); sedan.initialize(24,20.0,4); System.out.println ("The sedan can travel" + (1) +"miles./n"); System.out.println ("The sedan has" + (2) +"doors./n"); } } class automobile{ protected int miles_per_gallon; //汽车每加仑行驶公里数 (3) double fuel_capacity; //油箱容积 public void initialize(int in_mpg,int in_fuel){ miles_per_galion=in_mpg; fuel_capacity=in_fuel; } public int get_mpg( ){//提供一辆特定汽车每加仑公里数 return miles_per_gallon; } public double get_fuel( ){//提供油箱容积 return fuel_capacity; } public double travel_distance( ){//计算满油箱情况下的可行驶总公里数 return (4) ; } } class car (5) { private int Total_doors; public void initialize(int in_mpg,double in_fuel,int doors){ Total_doors=doors; miles_per_gallon=in_mpg;
[填空题]阅读以下说明和Java程序,将应填入 (n) 处的字句写在对应栏内。
[说明]
下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。
[Java程序]
public class MainJava
public static void main(String[] args)
Lot_size small=new Lot_size( );
Lot_size medium=new Lot_size( );
small.set(5,5,5,25);
medium.set(10,10,10,50);
System.out.println("For a small lot of area"
+small.get_area( )+"/n");
System.out.println("the actual crops are $"
+small.get_data2( )+"/n");
System.out.println("and ideal crops are $"
+small.get data( )+"/n");
System.out.println("For a medium lot of area"
+medium.get_area( )+“/n”);
System.out.println("the actual crops are $"
+medium.get_data2( )+"/n");
System.out.println ("and ideal crops are $"
+medium.get_data( )+"/n");
class Crop_assessment
private int actual_crop;
private int ideal_crop;
public void set(int
[单项选择]若运行以下程序时,从键盘输入ADescriptor<CR>(<CR>表示回车),则下面程序的运行结果是
#include <stdio.h>
main( )
char c;
int v0=1,v1=0,v2=0;
do switch(c=getchar( ))
case 'a':case 'A':
case 'e':case 'E':
case 'i':case 'I':
case 'o':case 'O':
case 'u':case 'U':v1+=1:
default:v0+=1;v2+=1;while(c!='/n');
printf("v0=%d,v1=%d,v2=%d/n",v0,v1,v2);
A. v0=7,v1=4,v2=7
B. v0=8,v1=4,v2=8
C. v0=11,v1=4,v2=11
D. v0=13,v1=4,v2=12

我来回答:

购买搜题卡查看答案
[会员特权] 开通VIP, 查看 全部题目答案
[会员特权] 享免全部广告特权
推荐91天
¥36.8
¥80元
31天
¥20.8
¥40元
365天
¥88.8
¥188元
请选择支付方式
  • 微信支付
  • 支付宝支付
点击支付即表示同意并接受了《购买须知》
立即支付 系统将自动为您注册账号
请使用微信扫码支付

订单号:

请不要关闭本页面,支付完成后请点击【支付完成】按钮
恭喜您,购买搜题卡成功
重要提示:请拍照或截图保存账号密码!
我要搜题网官网:https://www.woyaosouti.com
我已记住账号密码