Learn from this class (don't steal it). If you get any good ideas, use them.
A real program would have classes to handle I/O, but this isn't a real program.
File: Reverse.java
Code:
import javax.swing.JOptionPane // class for creating simple windowed interfaces
public class Reverse // class definition
{
public static void main(String[] args) // main function
{
String output = "", input = JOptionPane.showInputDialog("Please enter your name."); // user input
long i = 0; // simple definition
for (i = input.length(); i > 0; i--) // count down by 1 from the length of the input to 0
{
output += input.charAt(i); // adds character at i to output
}
JOptionPane.showMessageDialog(null, "Your name reversed is " + output + "."); // output
}
}
File: Entry.java
Code:
import javax.swing.JOptionPane; // class for creating simple windowed interfaces
public class Entry // class definition
{
public static void main(String[] args) // main function
{
String[] input = new String[9]; // new string array with 10 values
String output = "";
long i = 0, j = 0; // simple definitions
for (i = 0; i < 10; i++) // from 0 to 10, increasing by 1
{
input[i] = JOptionPane.showInputDialog("Please enter name number " + i + "."); // user input
}
for (j = 0; j < 10; j++) // from 0 to 10, increasing by 1
{
output += "Name number " + (i + 1) + " is " + input[i] + ".\n"; // adds to output
}
JOptionPane.showMessageDialog(output); // output
}
}
Hope this helps.
Bookmarks