问答题本程序的功能是监听对于菜单项和工具条按钮的操作。主窗口中有菜单、工具条和一个文字标签,菜单中有“文件”项,“文件”菜单中包括菜单项“新建”、“保存”、“打印”、“页面设置”和“退出”,工具条上包括按钮“新建”、“保存”、“打印”、“页面设置”和“退出”。单击任何一个菜单项或任何一个工具条按钮,文字标签都会显示哪个构件被选中。请更正题中带下划线的部分。运行结果如下图所示。注意:不改变程序的结构,不得增行或删行。importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclassadvanceextendsJFrameprivateJLabelactionlnfo;publicadvance(StringtitleText)setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);super(titleText);actionInfo=newJLabel("事件信息");JToolBartb=newJTooBar();Menufile=newMenu("文件");JMenuBarmb=newJMenuBar();mb.add(file);NewActionna=newNewAction(actionInfo);file.add(na);tb.add(na);SaveActionsa=newSaveAction(actionInfo);file.add(sa);tb.add(sa);PrintActionpta=newPrintAction(actionInfo);file.add(pra);tb.add(pra);PageSetActionpsa=newPageSetAction(actionInfo);file.add(psa);tb.add(psa);ExitActionea=newExitAction(actionInfo);file.add(ea);tb.add(ea);setJMenuBar(mb);Containercp=getContentPane();cp.setLayout(newBorderLayout());cp.add(tb);cp.add(actionInfo,BorderLayout.CENTER);setSize(350,200);setVisible(true);publicstaticvoidmain(String[]args)newadvance("advance"); classNewActionextendsAbstractAction JLabellabel;publicNewAction(JLabellabel)super("新建");this.label=label;publicvoidactionPerformed(ActionEvente)label.setText("您选择了新建"); classSaveActionextendsAbstractAction JLabellabel;publicSaveAction(JLabellabel)super("保存");this.label=label;publicvoidactionPerformed(ActionEvente)label.setText("您选择了保存"); classprintActionextendsAbstractAction JLabellabel;publicPrintAction(JLabellabel)super("打印");this.label=label;publicvoidactionPerformed(ActionEvente)label.setText("您选择了打印"); classPageSetActionextendsAbstractAction JLabellabel;publicpageSetAction(JLabellabel)super("页面设置");this.label=label;publicvoidactionPerformed(ActionEvente)label.setText("您选择了页面设置"); classExitActionextendsAbstractAction JLabellabel;publicExitAction(JLabellabel)super("退出");this.label=label;publicvoidactionPerformed(ActionEvente)label.setText("您选择了退出");
问答题本程序的功能是计算二维数组arr[][]={{34,21,45,67,20},{23,10,3,45,76},{22,3,79,56,50}}中的最小值,并输出。
public class exam_48{
public static void main(String[] args) {
int arr[][]={{34,21,45,67,20},{23,10,3,45,76},{22,3,79,56,50}};
int i=0;
int j=0;
int min=arr[0][0];
while(i<3){
while(______){
if(arr[i][j]<min)
min=arr[i][j];
j++;
}
______;
______;
}
System.out.println("The min:"+min);
}
}
问答题本题程序的功能是随机产生50个0~100间的随机数,并计算70~80间随机数的个数(包括70,不包括80)。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。 public class basic public static void main(String[] args) int result = 0; int i = 0; int randomNum; while (i<50) randomNum =______; if(______) result ++; ______; System.out.println("result =" + result);
问答题"不能构成三角形的3条边");
问答题在程序中,给出两个整数4和5,计算他们的和,并在屏幕上显示出来。请将程序补充完整。
注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。
______Add
{
private int a;
private int b;
public Add(int n1,int n2)
{
a=nl;
b=n2;
}
public int getAdd()
{
return a +b;
}
}
public class basic
{
public ______void main(String[] args)
{
int n1=4, n2=5;
Add aAddB=______Add(nl,n2);
System.out.println("4+5="+aAddB.getAdd());
}
}
问答题本程序中,用表格来表现某个月的月历,其中标题是从Sunday到Saturday,表格中的各项是可以修改的,如图所示。importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing,table.*;publicclassexam_60{publicstaticvoidmain(String[]args){try{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}catch(Exceptione){}JFrameframe=newCalendarTableFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.show();}}classCalendarTableFrameextendsJFrame{privatestaticfinalintWIDTH=500;privatestaticfinalintHEIGHT=I50;private______cells={{null,null,null,newInteger(1),newInteger(2),newInteger(3),newInteger(4)},{newInteger(5),newInteger(6),newInteger(7),newInteger(8),newInteger(9),newInteger(10),newInteger(11)},{newInteger(12),newInteger(13),newInteger(14),newInteger(15),newInteger(16),newInteger(17),newInteger(18)},{newInteger(19),newInteger(20),newInteger(21),newInteger(22),newInteger(23),newInteger(24),newInteger(25)},{newInteger(26),newInteger(27),newInteger(28),newInteger(29),newInteger(30),newInteger(31),null}};privateString[]columnNames={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};publicCalendarTableFrame(){setTitle("exam_60");setSize(WIDTH,HEIGHT);JTabletable=new______;getContentPane().add(newJScrollPane(table),BorderLayout.CENTER);}}
问答题本程序统计成绩及格的学生的平均分。学生分数分别为:59,60,48,73,92,69,34,85。
public class exam_46{
public static void main(String[] args){
int score[]={59,60,48,73,92,69,34,85};
int 1=score.length;
double sum=0;
int num=0;
int i=0;
while(i<1){
if(______){
sum=sum+score[i];
num++;
}
______;
}
double arerage=______;
System.out.println("The average:"+arerage);
}
}
问答题本题是一个Applet,功能是用鼠标画不同颜色的图形。页面中有5个按钮“画红色图形”、“画绿色图形”、“画蓝色图形”、“橡皮”和“清除”,单击前三个按钮中的一个,按住鼠标左键或右键在而板中拖动,就能画出对应颜色的线条,单击“橡皮”按钮,按住鼠标左键或右键在面板中拖动就能将面板中的图形擦除掉,单击“清除”按钮,就能将面板中所有的图形清除掉。 import java.applet.*; import java.awt.*; import java.awt.event.*; public class java3 extends Applet implements ActionListener int x=-1,y=-1,rubberNote=0,clearNote=0; Color c=new Color(255,0,0); int con=3; Button b_red,b_blue,b_green,b_clear,b_quit; public void init() addMouseMotionListener(this); b_red=new Button("画红色图形"); b_blue=new Button("画蓝色图形"); b_green=new Button("画绿色图形"); b_quit=new Button("橡皮"); b_clear=new Button("清除"); add(b_red); add(b_green); add(b_blue); add(b_quit); add(b_clear); b_red.addActionListener(this); b_green.addActionListener(this); b_blue.addActionListener(this); b_quit.addActionListener(this); b_clear.addActionListener(this); public void paint() if(x!=-1 g.fillOval(x,y,con,con); else if(rubberNote==1 else if(clearNote==1 public void mouseDragged(MouseEvent e) x=(int)e.getX();y=(int)e.getY();repaint(); public void mouseMoved(MouseEvent e) public void update(Graphics g) paint(g); public void actionPerformed(Event e) if(e.getSource()==b_red) rubberNote=0;clearNote=0;c=new Color(255,0,0); else if(e.getSource()==b_green) rubberNote=0;clearNote=0;c=new Color(0,255,0); else if(e.getSource()==b blue) rubberNote=0;clearNote=0;c=new Color(0,0,255); if(e.getSource()==b_quit) rubberNote=1;clearNote=0; if(e.getSource()==b_clear) clearNote=1;rubberNote=0;repaint();
问答题本程序是一个Applet,它的功能是在窗口上添加12×12个标签,并且标签的颜色为黑白相间(横向和纵向都是黑白相间的),如图所示。importjava.applet.*;importjava.awt.*;importjava.awt.event.*;publicclassexam_75extendsApplet{GridLayoutgrid;publicvoidinit(){grid=newGridLayout(12,12);setLayout(grid);Label______=newLabel[12][12];for(inti=0;i<12;i++){for(intj=0;j<12;j++){label[i][j]=______;if((i+j)%2==0)label[i][j].setBackground(Color.black);elselabel[i][j].setBackground(Color.white);add(label[i][j]);}}}}exam_75.html:<html><head><title>exam_75</title></head><body><appletcode="exam_75.class"width="400"height="500"></applet></body></html>
问答题注意:下面出现的“考生文件夹”均为%USER%。 在考生文件夹中存有文件名为Java_2.java的文件,该程序是不完整的,请在注释行“//**********Found**********”下一行语句的下画线地方填入正确内容,然后删除下画线,请勿删除注释行或改动其他已有语句内容。存盘时文件必须存放在考生文件夹下,不得改变原有文件的文件名。 本题的要求是: 创建二维数组并将其元素输出。 运行结果为 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 给定源程序: publ ic class Java_2 public static void main(String[]args) int[][]aMatrix=1, 1, 1, 1, 2, 2, 2, 2), 3, 3, 3, 3), 4, 4, 4, 4; int i=0;//循环变量 int j=0;//循环变量 //*********Found******** for(i=0;i<______;i++) for(j=0; j<aMatrix[i].length;J++) //*********Found******** System.out.print(______+""); System.out.println();
问答题System.exit(0);
问答题在程序中,用户输入一个文件名,根据用户输入显示相应文件的信息。
注意:请勿修改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();
}
}
}
问答题在程序中,用户使用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)
问答题本程序的功能是获取滚动条的值。窗口中有两个滚动条,一个垂直放置,另一个水平放置,当用鼠标拖动滚动条中滑块的位置时,文本标签将显示滚动条的值,如图所示。importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassexam_36extendsJPanel{JLabellabel;publicexam_36(){super(true);label=newJLabel();setLayout(newBorderLayout());JScrollBarhbar=newJScrollBar(JScrollBar.HORIZONTAL,30,20,0,300);JScrollBarvbar=newJScrollBar(JScrolIBar.VERTICAL,30,40,0,300);hbar.setUnitIncrement(2);hbar.setBlockIncrement(1);hbar.addAdjustmentListener(newMyAdjustmentListener());vbar.addAdjustmentListener(newMyAdjustmentListener());add(hbar,BorderLayout.SOUTH);add(vbar,BorderLayout.EAST);add(label,BorderLayout.CENTER);}classMyAdjustmentListenerextendsAdjustmentListener{publicvoidadjustmentValueChanged(AdjustmentEvente){label.setText("滚动条的值:"_+_getValue()_+_"____");repaint();}}publicstaticvoidmain(Strings[]){JFrameframe=newJFrame("exam_36");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setContentPane(exam_36());frame.setSize(200,200);frame.setVisible(true);}}
问答题private static int size;
问答题请完成下列Java程序:用JFrame建立—个窗口,再用网格布局管理器,对窗口布局进行控制,上面有2行2列4个按钮,要求对按钮的大小进行设定,宽度为150,高度为80。
注意:请勿改动main主方法和其他已有语句内容,仅在下划线处填入适当的语句。
源程序文件代码清单如下
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ex19_2
{
public static void main(String args[])
}
JFrame frm=new JFrame();
frm.setTitle("ex19_2");
Container cont=frm.getContentPane();
______;
cont.add(new JButton("button1"));
cont.add(new JButton("button2 "));
Dimension dimen=______;
JButton btn1=new JButton("button3");
btn1.setPreferredSize(dimen);
cont.add(btn1);
cont.add(new JButton("button4"));
frm.addWindowListener(new WindowAdapter()
{
public void winowClosing(WindowEvent we)
{
System.exit(0);
}
});
frm.pack();
frm.setVisible(true);
}
}
问答题下面是一个Applet程序,其功能是绘制三维矩形以使该矩形面凹下,并将图像放入凹下的矩形面中。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。程序运行结果如下:importjava.awt.*;importjava.applet.*;importjava.awt.image.*;importjava.util.*;importjava.net.*;/*<appletcode="ex16_3.class"width=800height=400></applet>*/publicclassex16_3extendsApplet{privateImageIMGonClick=over(this)title=放大;publicvoidinit(){URLurl=getCodeBase();IMGonClick=over(this)title=放大=getImage(url,"ex16_3.gif");MediaTrackermt=newMediaTracker();mt.addImage(IMGonClick=over(this)title=放大,1);try{mt.waitForAll();}catch(Exceptione){e.printStackTrace();}setBackground(Color.black);}publicvoidpaint(Graphicsg){intthick=3,x=10,y=10;{{U}}g.drawImage(IMGonClick=over(this)title=放大,x,y);{{/U}}g.setColor(Color.lightGray);intw=IMGonClick=over(this)title=放大.getWidth(this);inth=IMGonClick=over(this)title=放大.getHeight(this);for(inti=0;i<thick;i++){{U}}g.draw3DRect(x,y,w+(2*i),h+(2*i),true);{{/U}}}}{{B}}ex16_3.html{{/B}}<HTML><HEAD><TITLE>ex16_3</TITLE></HEAD><BODY><appletcode="ex16_3.class"width=800height=400></applet></BODY></HTML>
问答题请完成下列Java程序:假设某家银行,它可接受顾客的汇款,每做一次汇款,便可计算出汇款的总额。现有两个顾客,每人都分3次,每次50元将钱汇入。编写一个程序,模拟实际作业。要求实现2个类,一个是银行类,一个是顾客类。
注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
程序运行结果如下:
Customer2 :sum= 50
Customer1 :sum= 50
Customer1 :sum= 100
Customer2 :sum= 100
Customer1 :sum= 150
Customer2 :sum= 150
class bank{
private static int sum=0;
public static void add(int.n,char c){
int tmp=sum;
______________;
try{
Thread.sleep(((int) ((2000-500+1)*(Math.random())))+500);
}
catch(InterruptedException e){}
sum=tmp;
System.out.println("Customer"+c+" :sum= "+sum);
}
}
class customer extends Thread{
static char flag17_2 = '1';
public void run(){
char myflag17_2;
synchronized(this) {
myflag17_2 = flag17_2++;
}
for(int i=1;i<=3;i++)
______________________;
}
}
public class ex17_2{
public static void main(String args[]){
customer c1=new customer();
customer c2=new customer();
c1.start();
c2.start();
}
}
问答题基本操作题
下列程序中,实现将封装数据类型Integer和基本数据类型int之间的转换,以及Integer, int类型和String类型之间的转换。请将程序补充完整。
程序运行结果如下:
123
456
456
public class ex7_1 {
public static void main(String[] args) {
Integer intObj;
int n;
String s;
intObj=new Integer(123);
n=intObj. ;
System.out.println(Integer.toString(n));
s=new String("456");
intObj=Integer. ;
System.out.println(intObj. );
n=Integer.parseInt(s);
System.out.println(Integer.toString(n));
}
}
问答题本题的功能是对图形进行操作,包括旋转、移位、放大和剪切。窗口中有4个单选按钮和-个图形面板,图形面板中有-个矩形和该矩形移位操作后的图形,任选其中-个单选按钮,则图形面板中将显示该操作后的图形。
