haha

          2006年3月29日 #

          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 @ 2006-03-29 11:51 咖啡 閱讀(214) | 評(píng)論 (0)編輯 收藏

          主站蜘蛛池模板: 石城县| 苍溪县| 南雄市| 康马县| 鄂伦春自治旗| 五大连池市| 东源县| 乌兰察布市| 云南省| 开远市| 甘孜县| 阜平县| 东丽区| 大埔区| 寻乌县| 兴安县| 石首市| 启东市| 西丰县| 博湖县| 丰城市| 葵青区| 胶州市| 麻阳| 禹城市| 错那县| 长垣县| 陇南市| 梅河口市| 久治县| 西青区| 方正县| 龙游县| 天门市| 那曲县| 淳化县| 达日县| 恭城| 图木舒克市| 定州市| 靖边县|