zoukankan      html  css  js  c++  java
  • java 加法运算

    //find sum of two numbers
    
    import java.util.Scanner;
    
    public class Numbers {
    
        public static void main(String[] args) {
            int num1, num2, sum;
            Scanner ip = new Scanner(System.in);
            System.out.print("Enter num1: ");
            num1 = ip.nextInt();
            System.out.print("Enter num2: ");
            num2 = ip.nextInt();
            sum = num1 + num2;
            System.out.println("The sum of " + num1 + " and " + num2 + " is " + sum);
            ip.close();
        }
    
    }
    
    
    
    OUTPUT:
    Enter num1: 35
    Enter num2: 45
    The sum of 35 and 45 is 80

     2

    //find sum of n numbers
    
    import java.util.Scanner;
    
    public class Numbers {
    
        public static void main(String[] args) {
            int n, temp, sum = 0;
            Scanner ip = new Scanner(System.in);
            System.out.print("Enter the total number of input: ");
            n = ip.nextInt();
            for (int i = 1; i <= n; i++) {
                System.out.print("Enter input " + i + ": ");
                temp = ip.nextInt();
                sum = sum + temp;
            }
            System.out.println("The sum of all input numbers is: " + sum);
            ip.close();
        }
    
    }
    
    
    
    OUTPUT:
    Enter the total number of input: 5
    Enter input 1: 6
    Enter input 2: 3
    Enter input 3: 8
    Enter input 4: 2
    Enter input 5: 9
    The sum of all input numbers is: 28
  • 相关阅读:
    数论
    2019牛客暑期多校训练营(第七场)
    C++大数模板
    网络流
    2019 Multi-University Training Contest 6
    无聊的数列
    Can you answer on these queries III
    Interval GCD
    2733:判断闰年-poj
    题目1083:特殊乘法-九度oj
  • 原文地址:https://www.cnblogs.com/sea-stream/p/12095997.html
Copyright © 2011-2022 走看看