?? reverserapp.java
字號:
import java.io.*;
class StackX{
char[] a;
int size;
int top;
public StackX(int max){
size=max;
a=new char[max];
top=-1;
}
public void push(char value){
a[++top]=value;
}
public char pop(){
return a[top--];
}
public char peek(){
return a[top];
}
public boolean isempty(){
return (top==-1);
}
public boolean isfull(){
return (top==size-1);
}
}
class Reverser{
String output;
String input;
StackX s;
public Reverser(String in){
input=in;
}
public String doreverse(){
int length=input.length();
s=new StackX(length);
for(int i=0;i<length;i++){
char c=input.charAt(i);
s.push(c);
}
String output=" ";
while(!s.isempty())
{
char c;
c=s.pop();
output=c+output;
}
return output;
}
}
public class ReverserApp {
public static void main(String[] args)throws IOException
{
String output,input;
while(true)
{
System.out.println("please enter the input");
input=getString();
if(input.equals(""))
break;
Reverser r=new Reverser(input);
output=r.doreverse();
System.out.println("the result is"+" "+output);
}
}
public static String getString()throws IOException{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String s=br.readLine();
return s;
}
public static int getInt()throws IOException{
String s=getString();
return Integer.parseInt(s);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -