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

import java.util.Scanner; public class Test40032 { public static void main(String[] args) { int ri, repeat; int digit; long n, temp, pow; Scanner in = new Scanner(System.in); repeat = in.nextInt(); for (ri = 1; ri 0){ pow = (lo...

Scanner s = new Scanner(System.in);//通过new Scanner(System.in)创建一个Scanner,控制台会一直等待输入int a = s.nextInt();//调用Scanner的nextInt()方法获取输入的整数System.out.println(a*a);//输出这个数的平方

/** *一、求它是几位数,二、逆序打印出各位数字 */ 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...

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

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 static void main(String[] args) {//long a = 123456789L;long a = new Scanner(System.in).nextLong();int result = 0;while (a != 0) {result += a%10;//取个位数a /= 10;}System.out.println(result);}

import java.util.*; public class Number2 { public void run(int number){ if(number > 1000){ System.out.println("输入数字大于1000!"); System.exit(0); } int [] a= new int[3]; a[2] = number /100; a[1] = (number - a[2]*100)/10; a[0...

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