zoukankan      html  css  js  c++  java
  • Java 学习输入1234 求和

    输入任何整数都能求和

     1 import java.util.Scanner;
     2 
     3 /**
     4  * @author 作者anil E-mail:888@yirose.com
     5  * @date 创建时间:2017年3月23日 上午9:17:19
     6  * @version 1.0
     7  * @parameter
     8  * @since
     9  * @return
    10  * @tags
    11  *
    12  */
    13 
    14 public class totals {
    15     public static void main(String[] args) {
    16         
    17 //        int totals = 0;
    18 //        for (int i = 1; i <= 4; i=1) {
    19 //            System.out.print("请输入整数:");
    20 //            Scanner in = new Scanner(System.in);
    21 //            int op = in.nextInt();            
    22 //            totals += op;
    23 //            System.out.println(totals);
    24 //
    25 //        }        
    26         
    27         for (int i = 1; i <= 4; i=1) {
    28             int totals = 0;
    29             System.out.print("请输入整数:");
    30             Scanner in = new Scanner(System.in);
    31             int op = in.nextInt();    
    32             String s = String.valueOf(op);
    33             String[] a = s.split("");
    34             for (int j = 0; j < a.length; j++) {    
    35 //                int a1 = Integer.parseInt(a[j]);
    36                 totals += Integer.parseInt(a[j]);
    37 //                System.out.println(a1);                
    38             }    
    39             System.out.println(totals);            
    40 
    41         }
    42     }
    43 }
  • 相关阅读:
    linux fork, system, exec()
    wiegand 问题
    route/ip route的作用
    The Name/Origin of Country names
    修改 timezone
    Socket 广播
    IC卡的逻辑卡号和市民卡卡号
    32位和64位程序
    短连接和长连接
    各个公司的来源/The etymology of company
  • 原文地址:https://www.cnblogs.com/pxuan/p/6603730.html
Copyright © 2011-2022 走看看