public class Print{
public static void main(String args[])
{ int temp;
int a[]=new int[10];
for(int i=0;i<a.length;i++)
{ a[i]=System.in.read();
System.out.print(a[i]);
}
int k=a.length/2;
int M=a.length;
for(int i=0;i<k;i++,M--)
{
temp=a[i];
a[i]=a[m];
a[m]=temp;
}
for(int i=0;i<a.length;i++)
System.out.print(a[i]);
}
}
11 个解决方案
#1
public static void main(String[] arg) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input a string : ") ;
String s = br.readLine();
if(s != null)
{
StringBuffer sb = new StringBuffer(s);
System.out.print("reverse your string : "+sb.reverse());
}
}
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input a string : ") ;
String s = br.readLine();
if(s != null)
{
StringBuffer sb = new StringBuffer(s);
System.out.print("reverse your string : "+sb.reverse());
}
}
#2
楼上的是很好的,下面有个特别的方法如果用栈来做
public static void main(String[] arg) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input a string : ") ;
LinkedList ll = new LinkedList();
String s = br.readLine();
if(s != null)
{
String tmpstr = "";
char[] str1=s.toCharArray();
for(int i=0;i<str1.length;i++){
ll.addFirst(str1[i]);
}
for(int i=0;i<str1.length;i++){
tmpstr+=String.valueOf(ll.removeFirst());
}
System.out.println(tmpstr);
}
}
public static void main(String[] arg) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input a string : ") ;
LinkedList ll = new LinkedList();
String s = br.readLine();
if(s != null)
{
String tmpstr = "";
char[] str1=s.toCharArray();
for(int i=0;i<str1.length;i++){
ll.addFirst(str1[i]);
}
for(int i=0;i<str1.length;i++){
tmpstr+=String.valueOf(ll.removeFirst());
}
System.out.println(tmpstr);
}
}
#3
char[] str1=s.toCharArray();
for(int i=str1.length-1;i<=;i--){
System.out.println(char[i]);
}
这样不就可以反向输出了
for(int i=str1.length-1;i<=;i--){
System.out.println(char[i]);
}
这样不就可以反向输出了
#4
Scanner scanner=new Scanner(System.in);
String str=scanner.next();
StringBuffer sb=new StringBuffer(str);
StringBuffer result=sb.reverse();
System.out.println(result.toString());
String str=scanner.next();
StringBuffer sb=new StringBuffer(str);
StringBuffer result=sb.reverse();
System.out.println(result.toString());
#5
Scanner scanner=new Scanner(System.in);
String str=scanner.next();
StringBuffer sb=new StringBuffer(str);
StringBuffer result=sb.reverse();
System.out.println(result.toString());
======
这样就行了
String str=scanner.next();
StringBuffer sb=new StringBuffer(str);
StringBuffer result=sb.reverse();
System.out.println(result.toString());
======
这样就行了
#6
1是直接reverse2是自己写算法,看你要哪种
#7
太简单了。。。
#8
用linkedlist:
import java.io.*;
import java.util.*;
public class TEST1{
public static void main(String[] arg) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input a string : ") ;
LinkedList ll = new LinkedList();
String s = br.readLine();
if(s != null)
{
String tmpstr = "";
String []str1=new String[999];//设成999防止indexoutofboudsexception.
for(int i=0;i<s.length();i++)
str1[i]=s.substring(i,i+1);
for(int i=0;i<str1.length;i++){
ll.addFirst(str1[i]);
}
for(int i=0;i<str1.length;i++){
tmpstr+=String.valueOf(ll.removeFirst());
}
System.out.println(tmpstr);
}
import java.io.*;
import java.util.*;
public class TEST1{
public static void main(String[] arg) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input a string : ") ;
LinkedList ll = new LinkedList();
String s = br.readLine();
if(s != null)
{
String tmpstr = "";
String []str1=new String[999];//设成999防止indexoutofboudsexception.
for(int i=0;i<s.length();i++)
str1[i]=s.substring(i,i+1);
for(int i=0;i<str1.length;i++){
ll.addFirst(str1[i]);
}
for(int i=0;i<str1.length;i++){
tmpstr+=String.valueOf(ll.removeFirst());
}
System.out.println(tmpstr);
}
#9
hhtwya() ( ) 信誉:100 Blog 提醒你一下:
char[] str1=s.toCharArray();
for(int i=str1.length-1;i<=;i--){
System.out.print(char[i]);//这里是print不是println!
}
这样不就可以反向输出了
char[] str1=s.toCharArray();
for(int i=str1.length-1;i<=;i--){
System.out.print(char[i]);//这里是print不是println!
}
这样不就可以反向输出了
#10
public class Test{
public static void main (String args[ ]) throws IOException{
BufferedReader bf = new BufferedReader (new InputStreamReader(System.in));
String test =bf.readLine();
String s ="";
for(int i=test.length()-1;i>=0;i--){
String c = test.substring(i,i+1);
s=s.concat(String.valueOf(c));
}
System.out.println(s);
}
}
public static void main (String args[ ]) throws IOException{
BufferedReader bf = new BufferedReader (new InputStreamReader(System.in));
String test =bf.readLine();
String s ="";
for(int i=test.length()-1;i>=0;i--){
String c = test.substring(i,i+1);
s=s.concat(String.valueOf(c));
}
System.out.println(s);
}
}
#11
字符串转换称字符数组,然后反序输出数组的元素:
import java.io.*;
public class TestReverse{
public static void main(String args[]){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
char ch[]=new char[str.length()];
ch=str.toCharArray();
for(int i=ch.length-1;i>=0;i--){
System.out.print(ch[i]);
}
}catch(IOException e){}
}
}
import java.io.*;
public class TestReverse{
public static void main(String args[]){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
char ch[]=new char[str.length()];
ch=str.toCharArray();
for(int i=ch.length-1;i>=0;i--){
System.out.print(ch[i]);
}
}catch(IOException e){}
}
}
#1
public static void main(String[] arg) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input a string : ") ;
String s = br.readLine();
if(s != null)
{
StringBuffer sb = new StringBuffer(s);
System.out.print("reverse your string : "+sb.reverse());
}
}
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input a string : ") ;
String s = br.readLine();
if(s != null)
{
StringBuffer sb = new StringBuffer(s);
System.out.print("reverse your string : "+sb.reverse());
}
}
#2
楼上的是很好的,下面有个特别的方法如果用栈来做
public static void main(String[] arg) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input a string : ") ;
LinkedList ll = new LinkedList();
String s = br.readLine();
if(s != null)
{
String tmpstr = "";
char[] str1=s.toCharArray();
for(int i=0;i<str1.length;i++){
ll.addFirst(str1[i]);
}
for(int i=0;i<str1.length;i++){
tmpstr+=String.valueOf(ll.removeFirst());
}
System.out.println(tmpstr);
}
}
public static void main(String[] arg) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input a string : ") ;
LinkedList ll = new LinkedList();
String s = br.readLine();
if(s != null)
{
String tmpstr = "";
char[] str1=s.toCharArray();
for(int i=0;i<str1.length;i++){
ll.addFirst(str1[i]);
}
for(int i=0;i<str1.length;i++){
tmpstr+=String.valueOf(ll.removeFirst());
}
System.out.println(tmpstr);
}
}
#3
char[] str1=s.toCharArray();
for(int i=str1.length-1;i<=;i--){
System.out.println(char[i]);
}
这样不就可以反向输出了
for(int i=str1.length-1;i<=;i--){
System.out.println(char[i]);
}
这样不就可以反向输出了
#4
Scanner scanner=new Scanner(System.in);
String str=scanner.next();
StringBuffer sb=new StringBuffer(str);
StringBuffer result=sb.reverse();
System.out.println(result.toString());
String str=scanner.next();
StringBuffer sb=new StringBuffer(str);
StringBuffer result=sb.reverse();
System.out.println(result.toString());
#5
Scanner scanner=new Scanner(System.in);
String str=scanner.next();
StringBuffer sb=new StringBuffer(str);
StringBuffer result=sb.reverse();
System.out.println(result.toString());
======
这样就行了
String str=scanner.next();
StringBuffer sb=new StringBuffer(str);
StringBuffer result=sb.reverse();
System.out.println(result.toString());
======
这样就行了
#6
1是直接reverse2是自己写算法,看你要哪种
#7
太简单了。。。
#8
用linkedlist:
import java.io.*;
import java.util.*;
public class TEST1{
public static void main(String[] arg) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input a string : ") ;
LinkedList ll = new LinkedList();
String s = br.readLine();
if(s != null)
{
String tmpstr = "";
String []str1=new String[999];//设成999防止indexoutofboudsexception.
for(int i=0;i<s.length();i++)
str1[i]=s.substring(i,i+1);
for(int i=0;i<str1.length;i++){
ll.addFirst(str1[i]);
}
for(int i=0;i<str1.length;i++){
tmpstr+=String.valueOf(ll.removeFirst());
}
System.out.println(tmpstr);
}
import java.io.*;
import java.util.*;
public class TEST1{
public static void main(String[] arg) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input a string : ") ;
LinkedList ll = new LinkedList();
String s = br.readLine();
if(s != null)
{
String tmpstr = "";
String []str1=new String[999];//设成999防止indexoutofboudsexception.
for(int i=0;i<s.length();i++)
str1[i]=s.substring(i,i+1);
for(int i=0;i<str1.length;i++){
ll.addFirst(str1[i]);
}
for(int i=0;i<str1.length;i++){
tmpstr+=String.valueOf(ll.removeFirst());
}
System.out.println(tmpstr);
}
#9
hhtwya() ( ) 信誉:100 Blog 提醒你一下:
char[] str1=s.toCharArray();
for(int i=str1.length-1;i<=;i--){
System.out.print(char[i]);//这里是print不是println!
}
这样不就可以反向输出了
char[] str1=s.toCharArray();
for(int i=str1.length-1;i<=;i--){
System.out.print(char[i]);//这里是print不是println!
}
这样不就可以反向输出了
#10
public class Test{
public static void main (String args[ ]) throws IOException{
BufferedReader bf = new BufferedReader (new InputStreamReader(System.in));
String test =bf.readLine();
String s ="";
for(int i=test.length()-1;i>=0;i--){
String c = test.substring(i,i+1);
s=s.concat(String.valueOf(c));
}
System.out.println(s);
}
}
public static void main (String args[ ]) throws IOException{
BufferedReader bf = new BufferedReader (new InputStreamReader(System.in));
String test =bf.readLine();
String s ="";
for(int i=test.length()-1;i>=0;i--){
String c = test.substring(i,i+1);
s=s.concat(String.valueOf(c));
}
System.out.println(s);
}
}
#11
字符串转换称字符数组,然后反序输出数组的元素:
import java.io.*;
public class TestReverse{
public static void main(String args[]){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
char ch[]=new char[str.length()];
ch=str.toCharArray();
for(int i=ch.length-1;i>=0;i--){
System.out.print(ch[i]);
}
}catch(IOException e){}
}
}
import java.io.*;
public class TestReverse{
public static void main(String args[]){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
char ch[]=new char[str.length()];
ch=str.toCharArray();
for(int i=ch.length-1;i>=0;i--){
System.out.print(ch[i]);
}
}catch(IOException e){}
}
}