mdsk.net
当前位置:首页 >> 用JAVA语言编程输入一个整数的各位数字只和 >>

用JAVA语言编程输入一个整数的各位数字只和

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

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...

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;...

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...

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

求各位数字之和的程序如下: import java.util.Scanner; public class N { public static int sumDigits(long n){ int sum=0; while(n>0){ int m=(int)(n%10); sum=sum+m; n=n/10; } return sum; } public static void main(String[] args) { tr...

public double getNum(int n){ //申明,n必须大于0 double sum = 0.0; if (n

/** *一、求它是几位数,二、逆序打印出各位数字 */ 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 void static main(String [] args){ Scanner input =new Scanner(System.in); int i=0; int a[] =new int[]{}; while(i!=-1){ a[i] = input.next(); i++; } int sum=0; for(int i=0;i

public class A{ public static int s(int num){ int max = 0; while(num>10){ int tmp = num % 10; if(tmp>max){ max = tmp; } num = num / 10; } return max;}public static void main(String[] args){ System.out.println(s(562291));}}

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