decode.java
来自「Java 程序设计教程(第五版)EXAMPLESchap12的程序范例。」· Java 代码 · 共 46 行
JAVA
46 行
//********************************************************************
// Decode.java Author: Lewis/Loftus
//
// Demonstrates the use of the Stack class.
//********************************************************************
import java.util.*;
public class Decode
{
//-----------------------------------------------------------------
// Decodes a message by reversing each word in a string.
//-----------------------------------------------------------------
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
Stack word = new Stack();
String message;
int index = 0;
System.out.println ("Enter the coded message:");
message = scan.nextLine();
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 + -
显示快捷键?