My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.lineadecodigo.java.string;


/**
* @file InvertirFrase.java
* @version 1.0
* @author Linea de Codigo (http://lineadecodigo.com)
* @date 18/octubre/2009
* @url http://lineadecodigo.com/java/invertir-una-frase-en-java/
* @description Uso de una pila para invertir una frase.
*/



import java.util.Stack;
import java.util.StringTokenizer;

public class InvertirFrase {

public static void main(String[] args) {

// Cadena de texto
String sTexto = "En un lugar de la mancha de cuyo nombre no quiero acordarme";
System.out.println(sTexto);

// Particionador
StringTokenizer frase = new StringTokenizer(sTexto);

// Pila
Stack<String> pila = new Stack<String>();

while (frase.hasMoreTokens()) {
pila.push(frase.nextToken());
}

while (!pila.empty())
System.out.print(pila.pop() + " ");


}

}

Change log

r194 by vcuervo on Oct 18, 2009   Diff
Invertir una frase con una pila.
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 938 bytes, 42 lines
Powered by Google Project Hosting