java考试题急
圆的直径是矩形的宽吗,我做做。
public class Main
{ public static void main(String args[])
{
JX jx=new JX("求矩形去圆后面积");
}
}
import java.awt.*;
import java.awt.event.*;
import java.lang.String;
class JX extends Frame implements ActionListener
{
Label label;
TextField textLenth,textHeight;
TextArea 提示;
Button 确定;
JX(String s)
{
super(s);
setLayout(new FlowLayout());
textLenth=new TextField(8);
textHeight=new TextField(8);
label=new Label("请分别输入矩形的长与宽");
提示=new TextArea("这个程序的功能是将输入的长与宽的矩形"
"面积减去宽对应直径的圆的面积;长比宽大");
确定=new Button("确定");
确定.addActionListener(this);
add(label);
add(textLenth);
add(textHeight);
add(确定);
add(提示);
setBounds(100,100,450,200);
setVisible(true);
validate();
addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent windowevent){System.exit(0);}});
}
public void actionPerformed(ActionEvent e)
{
double m,n,s,s1,s2;
final double p = 3.14;
m=Double.parseDouble(textLenth.getText());
n=Double.parseDouble(textHeight.getText());
s1=m*n;
s2=n*n*p/4;
s=(s1-s2);
String result=Double.toString(s);
提示.setText(result);
}
}
JAVA基础编程题
package com.qiu.swing.layoutDemo;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JRootPane;
import javax.swing.JTextField;
/**
*
* @author Qiu
*
*/
public class TextDemo extends JFrame{
final JButton button_show = new JButton("显示");
final JButton button_clear = new JButton("显示");
final JTextField text = new JTextField();
final Container con = this.getContentPane();
public TextDemo() {
this.setTitle("HelloWorld!");
this.setSize(300, 160);
// 居中
this.setLocationRelativeTo(null);
this.setUndecorated(true); // 去掉窗口的装饰
this.setResizable(false);
this.getRootPane().setWindowDecorationStyle(
JRootPane.INFORMATION_DIALOG);// 采用指定的窗口装饰风格
// 文字居中
text.setSize(100, 20);
Box vbox = Box.createVerticalBox();
Box xbox0 = Box.createHorizontalBox();
xbox0.add(text);
xbox0.add(button_show);
xbox0.add(button_clear);
vbox.add(xbox0);
vbox.add(Box.createVerticalStrut(100));
con.setLayout(new BoxLayout(con, BoxLayout.X_AXIS));
con.add(vbox);
button_show.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
text.setText("HelloWorld");
}
});
button_clear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
text.setText("");
}
});
}
public static void main(String[] args) {
TextDemo home = new TextDemo();
home.setVisible(true);
}
}
JAVA基础测试题
1 跟java运行的机制有关,java先加载静态域,static int x=10; ,然后静态块static { x =5;},static { x/=3;}(虽然位置在后但先运行) ,然后静态方法static void main
所以x=10,x=15,x=5.
2 A因为int [ ] x = new int[25],数组建立后,每个元素默认值为0;x[24]=0;x[25] 下标越界,x[0]=0;
3 switch(i)不接受long型,int或者枚举型可以。i=Integer.parseInt(args[0]);虽然这样每课时i还是long型的。
4 c,没什么好说的,就是这么规定的!
一些java基础题
“爱!=付出”回答的很好,但是我感觉第4题只写javac java就可以的,因为问的只是命令,要是全部的话也应该是javac MyJavaApplication.java java MyJavaApplication