• 4


     1 //程序员:马相露
     2 
     3 package demo;
     4 import java.util.Scanner;
     5 public class Lk {
     6 
     7   public static void main(String[] args) {
     8 
     9     Scanner input = new Scanner(System.in);
    10     System.out.println("请输入一个0-1000之间的整数");
    11     int a =(int)input.nextDouble();
    12 
    13     if(a>999||a<0) {
    14       System.out.println("输入有误");
    15 
    16     }
    17     else if(a>0 && a<10){
    18       System.out.println("The sum of the digits is "+ a);
    19     }
    20     else if(a>9 && a<100) {
    21       int b=(a/10) + (a%10);
    22       System.out.println("The sum of the digits is "+ b);
    23     }    
    24     else if(a>99 && a<1000) {
    25       int c=(a/100)+(a%100)+(a%10%10); 
    26       System.out.println("The sum of the digits is "+ c);
    27     }
    28   }
    29 
    30 }

  • 相关阅读:
    C语言 · 新生舞会
    C语言 · 集合运算
    C语言 · 字符串的展开
    C语言 · 学做菜
    C语言 · 最长公共子序列 · 最长字符序列
    C语言 · 复数求和
    C语言 · 扶老奶奶过街
    C语言 · 删除重复元素
    1-3
    1-4
  • 原文地址:https://www.cnblogs.com/a718204806/p/8057351.html
Copyright © 2020-2023  润新知