nynw.net
当前位置:首页 >> 怎么用jAvA语言编写:计算并输出一个整数各位数字之... >>

怎么用jAvA语言编写:计算并输出一个整数各位数字之...

public class Test { public static void main(String[] args) { int a = 1203; int sum = 0; while(a / 10 != 0){ sum += a % 10; a = a / 10; }sum = sum + a; System.out.println("各位数字之和为" + sum); } } testing 各位数字之和为6 impo...

/** *一、求它是几位数,二、逆序打印出各位数字 */ import java.util.Scanner; public class Taskfor11{ public static void main(String[] args){ int inp; Scanner input=new Scanner(System.in); System.out.printf("输入数据:"); inp=inpu...

public class Test{ public static int calculate(Integer number){ String s = number.toString(); int length = s.length(); int sum = 0; for(int i = 0; i

代码如下: import java.util.Scanner;public class Test { public static void main(String[] args) { // 注:本程序只有输入正整数时才能正常执行,其他输入均可能出现非预期结果。 // 获取输入的数字 Scanner scanner = new Scanner(System.i...

package test1; import java.util.Scanner; public class Test6 { public static void main(String[] args) { Scanner input = new Scanner( System.in ); System.out.println("请输入一个数字:"); String str = input.next(); int result = 0;...

long sum = 0; for(int x = 1;x

利用Java应用程序编写要求输入两个整数并计算两个数据之和具体操作步骤如下: import java.util.Scanner public class Test { public static void main(String[] args) { System.out.print("请输入第一个整数:") Scanner s=new Scanner(System....

import java.util.Scanner; public class Qh{ public static void main(String[] args){ Scanner input=new Scanner(System.in); System.out.println("请输入:"); int a=input.nextInt(); int b=a/10000; int c=a%10000; int d=c/1000; int e=c...

import java.util.Scanner; public class TestDemo { public static void main(String[] args) { Scanner sc = new Scanner(System.in);//键盘输入数字 System.out.println("请输入一个数"); int a = sc.nextInt(); int temp=10; String str = S...

1、package test1; import java.util.Scanner; public class Test6 ;public static void main; Scanner input = new Scanner( System.in ); System.out.println; String str = input.next(); int result = 0; for( int i=0;i

网站首页 | 网站地图
All rights reserved Powered by www.nynw.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com