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

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

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

求各位数字之和的程序如下: 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...

import java.util.Scanner; public class Test { public static void main(String[] args) { System.out.print("请输入第一个整数:"); Scanner s=new Scanner(System.in); int a=s.nextInt(); System.out.print("请输入第二个整数:"); int b=s...

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 Taskfor11{ public static void main(String[] args){ int inp; Scanner input=new Scanner(System.in); System.out.printf("输入数据:"); inp=inpu...

楼上说没错,while(X)是先进行X判断然后再执行{语句体},而do..while则是先执行do{语句体},再判断while(X),这样会导致do..while比while执行语句体的次数多一次

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

public class IntTest { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int i = sc.nextInt(); if(i=1000){ //1 String s = new Integer(i).toString(); int sum = 0; for(int j = 0,k=s.length();j

public class SumUtil { public static int sum(int[] array){ int i = 0; if(array.length > 0){ for(int arr : array){ i += arr; } } return i; } public static void main(String[] args) { int[] array = {1,2,3,4,5}; System.out.print(su...

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