首页 > 其他 > 详细

课后作业

时间:2015-10-05 20:49:24      阅读:278      评论:0      收藏:0      [点我收藏+]

1.编写一个程序,用户输入两个数,求出其加减乘除,并用消息框显示计算结果。

代码:

import javax.swing.JOptionPane;

public class Da{

 

   public static void main(String[] args) {

    int n1=Integer.parseInt(JOptionPane.showInputDialog("Input number 1: "));

    int n2=Integer.parseInt(JOptionPane.showInputDialog("Input number 2: ")) ;   //获取从JOptionPane.showInputDialog对话框中输入的值,然后转换为int类型

    JOptionPane.showMessageDialog(null,"The sum is:"+(n1+n2)

          +"\n"+"The difference is:"+(n1-n2)

          +"\n"+"The product is:"+(n1*n2)

          +"\n"+"The division is:"+(n1/n2));

    }

 

 

截图:

 

技术分享技术分享

技术分享

2.验证字符串,示例程序每次运行时,都会生成不同的字符串。

public class Test1{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = null;
        while((str=scanner.nextLine())!=null){
        if(str.equals("exit")){    
                    break;}
    System.out.println(str);}
                        }
        }

 

课后作业

原文:http://www.cnblogs.com/tiantain1015/p/4856201.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!