haha

          java作業(yè)1

          package temp;
          /*1.編寫一個(gè)Application,接收用戶輸入的一行字符串,并重復(fù)輸出三行。
          ?*/
          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.編寫一個(gè)Application,接收用戶輸入的一行字符串,并重復(fù)輸出三行。
          ?*/
          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.編寫一個(gè)程序由用戶從鍵盤輸入整數(shù),計(jì)算它們的和,并顯示結(jié)果。
          ?* 當(dāng)用戶輸入了一個(gè)整數(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.編寫一個(gè)程序由用戶從鍵盤輸入整數(shù),計(jì)算它們的和,并顯示結(jié)果。
          ?* 當(dāng)用戶輸入了一個(gè)整數(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 on 2006-03-29 11:51 咖啡 閱讀(214) 評(píng)論(0)  編輯  收藏 所屬分類: java_homework


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 疏附县| 贵南县| 博兴县| 丹凤县| 北辰区| 建始县| 柳州市| 巩义市| 塔河县| 黔西| 顺平县| 镇原县| 桃源县| 绥化市| 乐至县| 南安市| 崇明县| 滦平县| 博爱县| 巴塘县| 长治市| 玛沁县| 枣强县| 浦江县| 攀枝花市| 航空| 广宗县| 饶河县| 富裕县| 万年县| 齐河县| 青阳县| 武乡县| 保山市| 博罗县| 张北县| 南丹县| 阳曲县| 南雄市| 财经| 湖北省|