1234 3 45
result
0 0 0 0 0 0 0 45 3 1234 //remove the front zero
package reverseApplet;
// An applet program to reverse a sequence of up to 10 integers
// entered into a text window, and write them into another text
// window. Based on TokenizerString class.
import java.applet.*;
import java.awt.*;
import java.util.*; // For StringTokenizer class
public class reversedApplet extends Applet {
TextField f, g;
public void init() { // This is a standard creation of 2 text fields.
f = new TextField("", 35);
f.setEditable(true);
add(f);
g = new TextField("", 35);
g.setEditable(false);
add(g);
add(new Button("Reverse me!"));
}
// A method to handle button clicks and reverse the sequence of numbers.
// Needs to be fixed to reverse only the actual number of integers entered.
public boolean action(Event e, Object arg) {
if (((Button) e.target).getLabel() == "Reverse me!") {
String input = f.getText();
String temp;
int fromText[] = new int[10];
StringTokenizer st = new StringTokenizer(input);
for (int i = 0; i < fromText.length; i++)
if (st.hasMoreTokens()) {
temp = st.nextToken();
fromText[i] = Integer.parseInt(temp);}
g.setText("");
for (int j = 0; j < fromText.length; j++)
g.setText(g.getText() + " " + fromText[fromText.length - j - 1]);
}
return true;
}
}

New Topic/Question
Reply



MultiQuote





|