java小测验:要求输入的词逆序小写排列输出 当按回车时停止
发布网友
发布时间:2024-09-28 17:33
我来回答
共1个回答
热心网友
时间:2024-10-04 15:54
import java.io.*;
public class Exam4{
public static void main(String[] args){
BufferedReader br = null;
String s = "";
String s1 = "";
char[] a = null;
try{
//用BufferedReader类包装InputStreamReader
br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入字符并以回车结束:");
//读入键盘输入
s = br.readLine();
StringBuffer ss = new StringBuffer(s);
ss.reverse();//利用StringBuffer类的翻转函数
s1 = ss.toString();
System.out.println("你输入的是:" + s);
System.out.println("翻转以后是:" + s1);
} catch (IOException e){
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
} finally{
try{
br.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
}
已测。
热心网友
时间:2024-10-04 15:52
import java.io.*;
public class Exam4{
public static void main(String[] args){
BufferedReader br = null;
String s = "";
String s1 = "";
char[] a = null;
try{
//用BufferedReader类包装InputStreamReader
br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入字符并以回车结束:");
//读入键盘输入
s = br.readLine();
StringBuffer ss = new StringBuffer(s);
ss.reverse();//利用StringBuffer类的翻转函数
s1 = ss.toString();
System.out.println("你输入的是:" + s);
System.out.println("翻转以后是:" + s1);
} catch (IOException e){
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
} finally{
try{
br.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
}
已测。