急!!如何用JAVA编写一个程序,可以使数位减少一位

来源:百度知道 编辑:UC知道 时间:2024/05/26 13:36:41
比如说你让使用者输入12345
然后他的结果会成为
1234
123
12
1

就是每次都少一位数,一直到只剩一位数

请不要使用LOOP之类的,我想要简单的数学方法或者其他的来编写

急用,谢谢!!

package test;
public class TT {
public static void main(String[] args) {
int a = 12345;
while(a/10!=0)
{
a = a/10;
System.out.println(a);
}
}

}

public static void test(String str){
int length = str.length();
for(int i=0;i<=length;i++){
System.out.println(str.substring(0, str.length()-i));
}
}

public class Example {
public static void main(String[] args) {
math(102356);
}

public static void math(int num) {
if (num < 10) {
System.out.println(num);
return;
} else {
int n = num / 10;
if (n >= 10)
System.out.println(n);
math(n);
}
}
}

package javaapplication1;
import java.util.Scanner;
public class java {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("请输入一个整数(>=10):");