decode.java
来自「java源程序 对初学者有很大的帮助 从简单到复杂」· Java 代码 · 共 44 行
JAVA
44 行
//********************************************************************
// Decode.java Author: Lewis/Loftus
//
// Demonstrates the use of the Stack class.
//********************************************************************
import java.util.Stack;
import cs1.Keyboard;
public class Decode
{
//-----------------------------------------------------------------
// Decodes a message by reversing each word in a string.
//-----------------------------------------------------------------
public static void main (String[] args)
{
Stack word = new Stack();
String message;
int index = 0;
System.out.println ("Enter the coded message:");
message = Keyboard.readString();
System.out.println ("The decoded message is:");
while (index < message.length())
{
// Push word onto stack
while (index < message.length() && message.charAt(index) != ' ')
{
word.push (new Character(message.charAt(index)));
index++;
}
// Print word in reverse
while (!word.empty())
System.out.print (((Character)word.pop()).charValue());
System.out.print (" ");
index++;
}
System.out.println();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?