zoukankan      html  css  js  c++  java
  • 作业

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

    源代码:

    package zy;
    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.showMessageDialog(null,"The sum is:"+(n1+n2)
    
              +"
    "+"The difference is:"+(n1-n2)
    
              +"
    "+"The product is:"+(n1*n2)
    
              +"
    "+"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);}
                            }
            }
  • 相关阅读:
    旅行计划
    两只塔姆沃斯牛
    迷宫
    异或序列
    异或之和
    素数个数
    SAC E#1
    [JSOI2010]Group 部落划分 Group
    [USACO12FEB]附近的牛Nearby Cows
    [HNOI2008]Cards
  • 原文地址:https://www.cnblogs.com/zyldbk/p/4859197.html
Copyright © 2011-2022 走看看