更多"【说明】本程序实现功能:读入两个整数,第1个数除以第2个数,声明当除数"的相关试题:
[简答题]【说明】本程序实现功能:读入两个整数,第1个数除以第2个数,声明当除数为零时抛出异常类DivideByZeroException。
public class DivideByZeroException (1)
public DivideByZeroException ( )
super("Attcmpted to divide by zero");
import java.io. *;
public class Example
private static int quotient(int numerator, in)/”t denominator) throws
DivideByZeroException
if (denominator==0)
throw (2) ;
return(numerator / denominator);
public static void main(String args[])
int number1=0, number2=0, result0;
try
System.out.print1n("Enter the first number:");
number1 = Integer. valueOf(Keyboard.getString( )).intValue( );
System.out.print1n("Enter the second number:");
number2 = Integer. Va1ueOf(Keyboard.getString( )).intValue( );
result = quotient(number1,number2);
catch (NumberFormatException e)
System.out.print1n("Invalid integer entered!");
Syst
[简答题]【说明】本程序ExceptionTester实现功能:读入两个整数,第1个数除以第2个数,之后输出。若第2个数为0,则自动进行异常处理。
程序如下:
(1) ;
public class ExceptionTester
public static void main(String args[])
int result;
int number[]=new int[2];
boolean valid; for(int i=0;i<2;i++)
valid= (2) ;
while(!valid)
try
System.out.println("Enter number"+(i+1));
number[i]=Integer.valueOf(Keyboard.getString( )).intValue( );
valid=true;
catch(NumberFormatExceptione)
System.out.println("Invalid integer entered.Please try again.");
by
result=number[0]/number[1];
System.out.print(number[0]+"/"+number[1]+"="+result);
catch( (3) )
System.out.println("Second number is 0,cannot do division!");
其中,Keyboard类的声明为:
impon java.io.*;
public class Keyboard
static BufferedReader inputStream=new (4)
(new Inp
[简答题]【说明】
本程序的功能是实现任意两个大整数的乘法运算,例如:
输入整数1:8934793850094505800243958034985058
输入整数2:234584950989689084095803583095820923
二者之积:
209596817742739508050978890737675662366433464256830959194834854876 8534
【C++代码】
#include<iostream.h>
const int MAXINPUTBIT=100;
const int MAXRESULTBIT=500;
class LargeNumber{
int i,j;
int temp;
int one[MAXINPUTBIT+1];
int onebit; //one的位数
int two[MAXINPUTBIT+1];
int twobit; //two的位数
int result[MAXRESULTBIT+1];
public:
LargeNumber( );
~LargeNumber( );
int inputone( ); //出错返叫0,否则返回1
int inputtwo( ); //同上
void multiplication( ); //乘
void clearresult( ); //清零
void showresult( ); //显示
};
LargeNumber∷LargeNumber( )
{
for(i=0;i<=MAXINPUTBIT;i++)
{
one[i]=0;
two[i]=0;
}
onebit=0;
twobit=0;
inputone( );
inputtwo( );
}
LargeNumber∷~LargeNumber( )
{
}
int LargeNumber∷inputone( )
{
char Number[MAXINPUTBIT+1];
cout<<"
[简答题]【说明】
本程序的功能是实现任意两个大整数的乘法运算,例如:
输入整数1:8934793850094505800243958034985058
输入整数2:234584950989689084095803583095820923
二者之积:
209596817742739508050978890737675662366433464256830959194834854876 8534
【C++代码】
#include<iostream.h>
const int MAXINPUTBIT=100;
const int MAXRESULTBIT=500;
class LargeNumber
int i,j;
int temp;
int one[MAXINPUTBIT+1];
int onebit; //one的位数
int two[MAXINPUTBIT+1];
int twobit; //two的位数
int result[MAXRESULTBIT+1];
public:
LargeNumber( );
~LargeNumber( );
int inputone( ); //出错返叫0,否则返回1
int inputtwo( ); //同上
void multiplication( ); //乘
void clearresult( ); //清零
void showresult( ); //显示
;
LargeNumber∷LargeNumber( )
for(i=0;i<=MAXINPUTBIT;i++)
one[i]=0;
two[i]=0;
onebit=0;
twobit=0;
inputone( );
inputtwo( );
La
[填空题]Java语言中常用异常类IOException是用来处理 【11】 异常的类。
[填空题][说明]
本程序实现对指定文件内的单词进行计数。其中使用二叉树结构来保存已经读入的不同单词,并对相同单词出现的次数进行计数。此二叉树的左孩子结点的字符串值小于父结点的字符串值,右孩子结点的字符串值大于父结点的字符串值。函数getword(char *filename,char*word)是从指定的文件中得到单词。char* strdup(char* s)是复制s所指向的字符串,并返回复制字符串的地址。
[函数]
#include <stdio. h>
#include<ctype. h>
#include <string.h>
#define MAXWORD 100
struct node
char *word;
int count;
struct node *left;
struct node *right;
struct node *addtree(struct node *p,char *w)
int cond;
if (p==NULL) /*向树中插入结点*/
p=(struct node*) malloc(sizeof(struct node));
p->word=strdup (w);
p->count=1;
(1) ;
else if((cond=strcmp (w,p->word))==0) (2) ;
else if (cond<0) p->left= (3) ;
else p->right= (4) ;
return p;
main( )
struct node *root;
char word [MAXWORD];
root=NULL;
filename="example .dat";
while getword(filename,word)! =EOF
root= (5) ;
[填空题]内存变量文件的扩展名为.MEM,若将保存在MM内存变量文件中的内存变量读入内存,实现该功能的命令是______。
[单项选择]自定义异常类的父类可以是()
A. Error
B. VirtuaMachineError
C. Exception
D. Thread
[简答题]【程序说明】
该程序定义了两个子函数strsort和strmerge。它们分别实现了将一个字符串按字母顺序排序和将两个字符串合并排序,并删去相同字符。在主函数里,先输入两个字符串s1和s2,然后调用strsort函数对它们分别排序,然后调用strmerge函数将s1和s2合并,将合并后的字符串赋给字符串s3,最后输出字符串s3。
【程序】
#include<stdio.h>
void strmerge(char,a,char *b,char *c) //将字符串a,b合并到字符串c中
{
char t,*w;
w=c;
while( (1) )
{//找到字符串a,b当前字符中较小的字符
if(*a< *b)
{
t= *a;
(2) ;
{
else if (*a>*b)
{
t= *b;
(3) ;
}
else //字符串a,b当前字符相等
{
t= *a;
a++;
b++;
}
if( (4) ) //开始,可直接赋值
*w=t;
else if(t!=*w)
//如果a,b中较小的当前字符与c中当前字符不相等,才赋值 (5) ;
}
if(*a!=/’/0’) //如果字符串a还没有结束,则将a的剩余部分赋给C
while(*a!=’/0’)
if(*a!=*w)
{
*(++w)=*a;
a++;
}
else
(6) ;
if(*6!=’/0’) //如果字符串b还没有结束,则将b的剩余部分赋给c
while(*b!=’/0’)
if(*b! = *w)
{
*(++w)=*b;
b++;
}
else
b++;
(7) ;
}
void strsort(char*s) //将字符串S中的字符
[填空题]下列程序实现的功能是:当在窗体上单击时,从键盘上读入5个学生的学号、姓名、英语成绩并存入到文件d:/stu1.dat中,然后从文件中读出第3个人的学号、姓名和英语成绩并显示在窗体中。
Type student
No As Long
Name As String * 20
English As Integer
End Type
Private Sub form_ Click ( )
Dim k As student, i As Integer
【8】
Open "d:/stu1. dat" for Random As #10 Len = Reclen
for i = 1 To 5
k. No= InputBox(“请输入学号”)
k. Name = InputBox (“请输入姓名”)
k. English= InputBox (“请输入英语成绩”)
【9】
Next i
【10】
Print k. No; k. Name; k. English
Close #10
End Sub
[简答题]【程序说明】
该程序定义了两个子函数strsort和strmerge。它们分别实现了将一个字符串按字母顺序排序和将两个字符串合并排序,并删去相同字符。在主函数里,先输入两个字符串s1和s2,然后调用strsort函数对它们分别排序,然后调用strmerge函数将s1和s2合并,将合并后的字符串赋给字符串s3,最后输出字符串s3。
【程序】
#include<stdio.h>
void strmerge(char,a,char *b,char *c) //将字符串a,b合并到字符串c中
char t,*w;
w=c;
while( (1) )
//找到字符串a,b当前字符中较小的字符
if(*a< *b)
t= *a;
(2) ;
else if (*a>*b)
t= *b;
(3) ;
else //字符串a,b当前字符相等
t= *a;
a++;
b++;
if( (4) ) //开始,可直接赋值
*w=t;
else if(t!=*w)
//如果a,b中较小的当前字符与c中当前字符不相等,才赋值 (5) ;
if(*a!=/’/0’) //如果字符串a还没有结束,则将a的剩余部分赋给C
while(*a!=’/0’)
if(*a!=*w)
*(++w)=*a;
a++;
else
(6) ;
if(*6!=’/0’) //如果字符串b还没有结束,则将b的剩余部分赋给c
while(*b!=’/0’)
if(*b! = *w)