tnfh.net
当前位置:首页 >> JAvA中从键盘下输入任意整数,逆序输出其各位数字 >>

JAvA中从键盘下输入任意整数,逆序输出其各位数字

public static void main(String []args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); while(n!=0){ System.out.print(n%10); n/=10; }}

可以先将输入的10个数字存放到数组中然后遍历输出 public static void main(String[] args) { int[] strs={1,2,3,4,5,6,7,8,9,10};//存放输入数据的数组 //正序输出 for (int i = 0; i < strs.length; i++) { System.out.println(strs[i]); } //...

其实就这么简单,有注释。也没有复杂的语句。 import java.util.Scanner;import java.lang.System;public class fds {public static void main(String[] args) {Scanner sc = new Scanner(System.in);String inputStr = sc.next(); // 获取控制...

public static void main(String[] args) { System.out.println("请输入3位的整数"); Scanner in = new Scanner(System.in); int cr = in.nextInt(); int b = cr / 100; int s = cr / 10 %10; int g = cr % 10; System.out.println("倒序:"+g+"...

public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("输入任意正整数:"); StringBuffer sb = new StringBuffer(input.next()); sb.reverse(); System.out.print("逆序为:"); System.out.pri...

import java.util.Scanner;public class Array {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int [] a = new int[10];int count = 0;System.out.println("请输入10个整数");while (true) {if(scanner.ha...

int i = 12343465; int m = 0; while (i != 0) { m =i%10; System.out.print(m); i = i/10; }

import java.util.Scanner; public class test1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a[] = new int [10]; for(int i=0;i=0;j-- ){ System.out.print(a[j]+" "); } } } 这个应该是你要的吧

Scanner scan = new Scanner(System.in); System.out.println("输入一个5位或5位以下的数字"); int num = scan.nextInt(); String s = String.valueOf(num); System.out.println("输入数字的长度为:"+s.length()); for(int i=s.length()-1;i>=0...

import java.util.*;public class demo {public static void main(String[] args) {Scanner sc = new Scanner(System.in);String line = sc.nextLine();System.out.println(new StringBuilder(line).reverse().toString());}}

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