一Java题目,抱歉我新手

来源:百度知道 编辑:UC知道 时间:2024/09/28 09:24:39
一Java题目,抱歉我新手。要求输入一任意正整数,之后得到一该正整数的倒序数,注意是正整数,如123输出321,还有就是我现在Java没学到那么远,所以只能在会循环的基础上求高手解答

import java.io.*;
public class Test {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();

try {
int i = Integer.parseInt(str);
if(i < 0) {
throw new Exception();
}
} catch (Exception e) {
System.out.println("请输入数字,数字必须位于0到" + Integer.MAX_VALUE + "之间");
System.exit(-1);
}
System.out.println(new StringBuilder(str).reverse());
}
}

class A{
public static void main(String[] args){
int m,a,b,c;
a=(int)m/100;
b=(int )m/10-10*a;
c=m%10;
System.out.println("the new number is"+c+b+a);
}
}

这个是我自己写,写的不好

import java.io.*;
public class Test
{
//任意输入一个整数,输出它的逆序,如123输出321
public static void main(String args[]) throws Exception
{
BufferedReader