实验一: //1.编写一个程序,能够从键盘上接收两个数字,然后计算这两个数的乘积并打印输出; //提示:从键盘输入采用System.in对象。 import java.io.*; public class test1 { public static void main(String[] args)throws IOException { String a,b; int s,t; BufferedReader in =new Buff...
帮帮忙,谢谢了。面向对象程序设计JAVA试题
我的实训题,不知道对你有没有帮助哈。包含了参考答案。 实验一: //1.编写一个程序,能够从键盘上接收两个数字,然后计算这两个数的乘积并打印输出; //提示:从键盘输入采用System.in对象。 import java.io.*; public class test1 { public static void main(String[] args)throws IOException { String a,b; int s,t; BufferedReader in =new BufferedReader( new InputStreamReader(System.in)); a=in.readLine(); s=Integer.parseInt(a); b=in.readLine(); t=Integer.parseInt(b); System.out.println(s*t); } } //2.编写一个程序,从文本框接收两个数字,然后计算这两个数的乘积并打印输出; //提示:两个输入框加一个按钮,通过点击按钮来触发事件。 //编写一个程序,从文本框接收两个数字,然后计算这两个数的乘积并打印输出 import java.io.*; import java.awt.*; import java.awt.event.*; public class Test3 extends Frame implements ActionListener{ TextField f1=new TextField(10); TextField f2=new TextField(10); Button bt=new Button("等于"); public Test3() { setLayout(new FlowLayout()); add(f1); add(f2); add(bt); bt.addActionListener(this); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); pack(); setVisible(true); } public static void main(String[] args){ Test3 t=new Test3(); } public void actionPerformed(ActionEvent e) { System.out.println(Integer.parseInt(f1.getText()) * Integer.parseInt(f2.getText())); } } 实验二: //1.编写用户输入的三个整数,比较并输出其中的最大值和最小值;(if) import java.io.*; public class Test3{ public static void main(String args[])throws IOException{ int m,n,p; String x,y,z; BufferedReader in =new BufferedReader( new InputStreamReader(System.in)); x=in.readLine(); m=Integer.parseInt(x); y=in.readLine(); n=Integer.parseInt(y); z=in.readLine(); p=Integer.parseInt(z); if(m>=n&&m>=p){ System.out.println("the max is"+m); if(n>=p){ System.out.println("the min is"+p); } else System.2014-09-17