haha

          2006年3月29日 #

          java作業(yè)1

          package temp;
          /*1.編寫一個Application,接收用戶輸入的一行字符串,并重復輸出三行。
          ?*/
          import java.awt.event.ActionEvent;
          import java.awt.event.ActionListener;
          import java.io.*;
          import javax.swing.*;

          public class Input extends JFrame implements ActionListener {
          ?/**
          ? *
          ? */
          ?private static final long serialVersionUID = 1L;

          ?static JTextField text_in;

          ?static JTextArea text_out;

          ?static JButton in;

          ?String s;

          ?public static void pain() {
          ??Input frame = new Input();
          ??frame.setLayout(null);
          ??frame.setTitle("Input");
          ??text_in = new JTextField("please input a string", 1);
          ??text_in.setBounds(10,10,300,30);
          ??frame.add(text_in);
          ??in = new JButton("in");
          ??in.setBounds(10,150,50,30);
          ??frame.add(in);
          ??in.addActionListener(frame);

          ??text_out = new JTextArea(3, 993);
          ??text_out.setBounds(10,50,300,90);
          ??frame.add(text_out);
          ??frame.pack();
          ??frame.setVisible(true);
          ??
          ?}

          ?public static void main(String args[]) throws IOException {
          ??Input.pain();
          ?}

          ?public void actionPerformed(ActionEvent e) {
          ??// TODO Auto-generated method stub
          ??if (e.getActionCommand().equals("in"))
          ???s = text_in.getText();
          ??text_out.setText(s + "\n" + s + "\n" + s);
          ?}
          }
          /*1.編寫一個Application,接收用戶輸入的一行字符串,并重復輸出三行。
          ?*/
          import java.io.*;
          public class Input {
          ?public static void main(String args[]) throws IOException {
          ??BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
          ??String s = bf.readLine();
          ??// for(int i=0;i<3;i++)
          ??// System.out.println(s);
          ??System.out.print(s + "\n" + s + "\n" + s);
          ?}
          }
          package temp;

          /*2.編寫一個程序由用戶從鍵盤輸入整數(shù),計算它們的和,并顯示結果。
          ?* 當用戶輸入了一個整數(shù)并按下回車鍵后,該數(shù)被程序讀入并累加到總和中。
          ?*/
          import java.io.*;
          public class InputSum {
          ?static int sum;
          ?public static void main(String args[]) throws IOException {
          ??BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
          ??String ss = bf.readLine();
          ??String input=ss;
          ??int s = Integer.parseInt(ss);
          ??for (;;) {
          ???if (!ss.endsWith("q")) {
          ????s = Integer.parseInt(ss);
          ????sum = sum + s;
          ???} else {
          ????System.out.print(input+"="+sum);
          ????System.exit(0);
          ???}
          ???ss = bf.readLine();
          ???if(!ss.endsWith("q"))input+="+"+ss;
          ??}
          ?}
          }
          package temp;
          /*2.編寫一個程序由用戶從鍵盤輸入整數(shù),計算它們的和,并顯示結果。
          ?* 當用戶輸入了一個整數(shù)并按下回車鍵后,該數(shù)被程序讀入并累加到總和中。
          ?*/
          import javax.swing.*;
          public class InputSum2 {
          ?static String num1, num2;
          ?static int n1, n2,sum;

          ?public static void main(String args[]) {
          ??num1 = JOptionPane.showInputDialog("Please input a number");
          ??num2=JOptionPane.showInputDialog("please input second number");
          ??n1=Integer.parseInt(num1);
          ??n2=Integer.parseInt(num2);
          ??sum=n1+n2;
          ??JOptionPane.showMessageDialog(null, num1+"+"+num2+"="+sum);
          ?}
          }

          posted @ 2006-03-29 11:51 咖啡 閱讀(214) | 評論 (0)編輯 收藏

          僅列出標題  
          主站蜘蛛池模板: 垣曲县| 吕梁市| 积石山| 信宜市| 寿阳县| 沅江市| 石景山区| 城步| 友谊县| 平武县| 凉山| 文化| 永安市| 潢川县| 贵阳市| 镇康县| 当雄县| 华宁县| 中江县| 利川市| 海伦市| 台东县| 大英县| 青岛市| 无极县| 壤塘县| 聊城市| 梨树县| 昌平区| 桃江县| 博野县| 治县。| 宕昌县| 灌阳县| 库尔勒市| 勐海县| 丰原市| 广宗县| 池州市| 南乐县| 江川县|