更多"下列程序中,用户使用JOptionPane输入一个二维数组的行数,程序"的相关试题:
[简答题]下列程序中,用户使用JOptionPane输入一个二维数组的行数,程序随机生成每一行的列数,并对其赋值。最后显示这个二维数组。请填写横线处的内容。
注意:请勿改动main( )主方法和其他已有语句内容,仅在横线处填入适当语句。
import javax.swing.*;
public class Examplel_10
{
public static void main (String[] argv)
{
String sDimU = JOptionPane. showInputDialog ("请输入数组的行数");
int iDimU = __________ (sDimU);
int [] [] numbers = new int[iDimU] [];
for(int i = 0; i < iDimU; i++)
{
int k = (int) (Math.random( ) *5+1);
numbers [i] = ____________;
}
for(int i = O; i < iDimU; i++)
{
for(int j = 0; _________; j++)
{
numbers[i] [j] = (int) (Math.random( )*100);
System.out.print(numbers[i] [j] + " ");
}
System.out.println( );
}
System.exit(O);
}
}
[简答题]在程序中,用户使用JOptionPane输入一个二维数组的行数,程序随机生成每一行的列数,并对其赋值。最后显示这个二维数组。请填写横线处的内容。
注意:请勿修改main( )主方法和其他已有语句内容,仅在横线处填入适当语句。
import javax.swing.*;
public class basic
public static void main(String[] args)
String sDimU=JOptionPane.showInputDialog("请输入数组的行数");
int iDimU=______(sDimU);
int [].[] numbers=new int[iDimU] [];
for(int i=0; i<iDimU; i++)
int k=(int) (Math.random( )*5+1);
numbers[i]=______;
for(int i=0; i<iDimU; i++)
for(int j=0;______; j++)
numbers[i] [j]=(int) (Math.random( )*l00);
System.out.print(numbers[i] [j]+" ");
System.out.println ( );
System.exit(O)
[简答题]【程序功能】
将一个二维数组中的若干行数据按要求插入到另一个二维数组中。
【编程要求】
1.定义符号常量N代表4
2.编写函数int insert_row(int a[][N],int n,int b[][N],int m)。已知形参a指向的二维数组(简称a数组)前n行数据已按每行数据之和升序排列,形参b指向的二维数组中有m行数据。insert_row函数实现将b数组中m行数据插入到a数组中,完成插入操作后a数组中所有行的数据仍按每行数据之和升序排列。函数返回a数组中有效数据的行数。
3.编写main函数。函数功能是声明两个二维数组x和y并用测试数据初始化,用x和y
数组作为实参调用insert_row函数将y数组中的两行数据插入到x数组中。输出x数组中全部数据到屏幕及文件myf2.out中。最后将考生本人的准考证号字符串输出到文myf2.
out中。
【测试数据与运行结果】
测试数据:
x数组原数据:
2 2 3 4
9 10 11 12
y数组数据:
1 3 5 7
5 10 15 20
屏幕输出:
2 2 3 4
1 3 5 7
9 10 11 12
5 10 15 20
[单项选择]下列程序要求用户输入一个年份,并能够判断用户输入的年份是否是闰年,横线处应填( )。
Sub EnSure( )
Dim year As Integer
year=Val(InputBox("请输入年份:"))
If(year Mod 4=0______year Mod 100<>0)______(year Mod 400=0)Then
Print"您输入的是闰年"
Else
Print"不是闰年,是普通年份"
End If
End Sub
A. And And
B. And Or
C. Or Or
D. Or Of
[单项选择]下列程序要求用户输入一个年份,并能够判断用户输入的年份是否是闰年,下划线处应填( )。
Sub EnSure( )
Dim year As Integer
year=Val(InputBox("请输入年份:"))
If(year Mod 4=0 ______ year Mod 100<>0) ______ (year Mod 400=0) Then
Print "您输入的是闰年"
Else
Print "不是闰年,是普通年份"
End If
End Sub
A. And And
B. And Or
C. Or Or
D. Or Or
[单项选择]下列程序要求用户输入一个年份,并能够判断用户输入的年份是否是闰年,横线处应填( )。
Sub EnSure( )
Dim year As Integer
year=Val(InputBox("请输入年份:"))
If(year Mod 4=0______year Mod 100<>0)______(year Mod 400=0)Then
Print"您输入的是闰年"
Else
Print"不是闰年,是普通年份"
End If
End Sub
A. And And
B. And Or
C. Or Or
D. Or Of
[单项选择]下列程序要求用户输入一个年份,并能够判断用户输入的年份是否是闰年,下划线处应填( )。
Sub EnSure( )
Dim year As Integer
year=Val(InputBox("请输入年份:"))
If(year Mod 4=0__year Mod 100 <> 0)__(year Mod 400=0) Then
Print "您输入的是闰年"
Else
Print "不是闰年,是普通年份"
End If
End Sub
A. And And
B. And Or
C. Or Or
D. Or Or
[简答题]【说明】清点盒子。本程序当用户输入一个整数值时,一切正常;当输入其他数值时,程序就出错。现在已做了改进,请填空。
import java. text. NumberFormat;
Public class InventoryLoop
{
public static void main(String args[])
{
String numBoxesIn;
Int numBoxes;
Double boxPrice=3.25;
Boolean gotGoodInput=false;
NumberFormat currency=NumberFormat. (1) ;
do
{
System.out. print(“How many boxes do we have”);
numBoxesIn=DummiesIO. (2) ;
try
{
numBoxes=Integer.parseInt( (3) );
system. out. print("The value is");
system.out. println(currency, format (numBoxes*boxPrice));
gotGoodInput=true;
catch( (4) )
{
System.out.println( );
System.out. println(That’s not a number.");
}
}while( (5) );//输入不正确时
System. out.println("That’s that.");
}
}
[填空题]设某个程序中要用到一个二维数组,要求数组名为A,类型为字符串类型,第一维下标从1到5,第二维下标从-2到6,则相应的数组声明语句为 【9】
[简答题]在程序中,用户输入一个文件名,根据用户输入显示相应文件的信息。
注意:请勿修改main( )主方法和其他已有语句内容,仅在横线处填入适当语句。
______java.io.*;
public class basic
{
public static void main(String[] args)
{
InputStreamReader reader;
BufferedReader in;
System.out.println("请输入文件名: ");
try
{
reader=new InputStreamReader(______);
in=new BufferedReader(reader);
String filename=in.readLine( );
File file=new File(filename);
System.out.println("文件名:"+file.______);
System.out.println("路径:"+file.getAbsolutePath( ));
System.out.println("大小:"+file.length( ));
}
catch(Exception e)
{
e.printStackTrace( );
}
}
}
[简答题]在程序中,用户输入一个文件名,根据用户输入显示相应文件的信息。
注意:请勿修改main( )主方法和其他已有语句内容,仅在横线处填入适当语句。
______java.io.*;
public class basic
public static void main(String[] args)
InputStreamReader reader;
BufferedReader in;
System.out.println("请输入文件名: ");
try
reader=new InputStreamReader(______);
in=new BufferedReader(reader);
String filename=in.readLine( );
File file=new File(filename);
System.out.println("文件名:"+file.______);
System.out.println("路径:"+file.getAbsolutePath( ));
System.out.println("大小:"+file.length( ));
catch(Exception e)
e.printStackTrace( );
[填空题]如下程序声明了一个二维图形类TwoDShape,从其派生出矩形类Rec。
#include<iostream>
#include<string>
using namespaee std,
class TwoDShape{// 二维图形类
char name[20];
public:
TwoDShape (char * n="unknown") {
strcpy(name, n);
}
Char * getName( ){return name;}
【 】 =0;
};
class Rec: public TwoDShape{
double width, height
public:
Rec(double w-=0. 0,double h=0. 0):TwoDShape("rectangle")
{ width=w; height=h; }
double getWidth( ) {return width;}
double getHeight( ) {return height;}
double area( ) {return width * height;}
};
int main( ) {
TwoDShape * shape;
Shape=new Rec(2.1,3.0);
cout<<"object is"<<shape->getName( )<<"/n";
cout<<"Area is"<<shape->area( )<<"/n";
return 0
}
请将程序补充完整,使程序在运行时输出:
abject is triangle
Area is 6.3