Skip to content

Instantly share code, notes, and snippets.

@MrBean83
Created May 12, 2015 16:07
Show Gist options
  • Select an option

  • Save MrBean83/eed68427ba38ae7dc9c2 to your computer and use it in GitHub Desktop.

Select an option

Save MrBean83/eed68427ba38ae7dc9c2 to your computer and use it in GitHub Desktop.

Revisions

  1. MrBean83 created this gist May 12, 2015.
    20 changes: 20 additions & 0 deletions StringOddEven.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    import javax.swing.JOptionPane;

    public class StringOddEven {
    public static void main(String args[]) {
    String input = JOptionPane.showInputDialog("Please enter a string.");
    int length = input.length();

    if (length % 2 == 0) {
    System.out.println(input);
    } else {
    int i = length - 1;

    // Using a DO-WHILE loop for this program.
    do {
    System.out.print(input.charAt(i));
    i--;
    } while (i >= 0); // end do-while
    } // end if
    } // end main
    } // end class