没有合适的资源?快使用搜索试试~ 我知道了~
java上机题汇编java上机题汇编.doc
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 8 浏览量
2022-06-09
19:20:47
上传
评论
收藏 2.63MB DOC 举报
温馨提示
试读
33页
java上机题汇编java上机题汇编
资源推荐
资源详情
资源评论
11.1--------------------------------------------------------------------------------------------------方法的调用
调用 method()的方法
public class ex1_1 {
public static void main(String[] args) {
int n1=2,n2=3;
ex1_1 obj1_1=new ex1_1();
obj1_1.method(n1,n2); // 将
n1,n2 的值赋予了
x,y
}
public void method(int x,int y){
System.out.println((double)x/y); // 改变了
x/y
的精度
System.out.println(x*y);
}
}
12.1
import java.io.*;
public class ex2_1 {
public static void main(String[] args) {
File file2_1 = new File("ex2_1.java");
System.out.println("name: " + file2_1.getName());
System.out.println("path: " + file2_1.getPath());
System.out.println("length: " + file2_1.length());
}
}
//Java_2.java
import java.awt.*;
import java.awt.event.*;
public class Java_0602 extends Frame implements WindowListener {
//*********Found********
public Java_0602() {
setLayout(new FlowLayout());
add(new Button("Button 1"));
add(new Button("2"));
add(new Button("Button 3"));
//*********Found********
addWindowListener (this);
}
public static void main(String args[]) {
Java_0602 window = new Java_0602();
window.setTitle("AWT Test");
window.pack();
window.show();
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowClosed(WindowEvent e) { }
public void windowOpened(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
}
//Java_2.java
import java.awt.*;
import java.awt.event.*;
public class Java_0602 extends Frame implements WindowListener {
//*********Found********
public Java_0602() {
setLayout(new FlowLayout());
add(new Button("Button 1"));
add(new Button("2"));
add(new Button("Button 3"));
//*********Found********
addWindowListener (this);
}
public static void main(String args[]) {
Java_0602 window = new Java_0602();
window.setTitle("AWT Test");
window.pack();
window.show();
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowClosed(WindowEvent e) { }
public void windowOpened(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
}
import java.text.*;
public class Java_0603{
public static void main(String[] args){
Person p = new Student("王甜甜", "计算机科学");
System.out.println(p.getName() + ", "+ p.getDescription());
}
}
abstract class Person{
public Person(String n){
name = n;
}
//*********Found********
public abstract String getDescription();
public String getName(){
return name;
}
private String name;
}
//*********Found********
class Student extends Person{
public Student(String n, String m){
super(n);
major = m;
}
//*********Found********
public String getDescription(){
return "学生专业是:" + major;
}
private String major;
}
1.1-----------------------------------------------------------------对话框
import
javax.swing.JOptionPane; /
/ 引入
JoptionPane
类
public class Java_0101 {
public static void
main( String args[] ) {
int x, y, result;
String xVal, yVal;
xVal =
JOptionPane.showInputDialog( "输入第 1 个整数:" ); //为对话框设置标签
yVal = JOptionPane.showInputDialog( "输入第 2 个整数:" );
//*********Found********
x = Integer.parseInt(xVal ) ; //获取对话框中的值
y = Integer.parseInt( yVal );
result = x * y;
//*********Found********
JOptionPane.showMessageDialog( null, "两个数的积: " + result ); //弹出信息窗口
System.exit( 0 ); //能够关闭窗口
}
}
import javax.swing.*;
public class Java_0501{
public static void main( String args[] ){
String s1 = new String( "您好! " ),
s2 = new String( "祝您生日快乐!" ),
output;
output = "s1 = " + s1 + "\ns2 = " + s2;
//*********Found********
output += "\n\n s1.concat( s2 ) = " + s1.concat( s2 );
output += "\ns1 连接前= " + s1;
//*********Found********
JOptionPane.showMessageDialog( null, output,
"显示字符串连接",
JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 );
}
}
完成一个程序
剩余32页未读,继续阅读
资源评论
oligaga
- 粉丝: 52
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功