I am new to Java and really lost. Can someone help me out?
I am not sure what is wrong here.

import java.io.*;
import java.util.Scanner;    //For the scanner

public class practice 
    {
    public static void main(String[] args) throws Exception{

    }
    BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
    String str;
    {
        //Create a scanner object to read input
        Scanner keyboard = new Scanner(System.in);
        try {
        System.out.print("Enter your name:");
        str=new String();
        String str=  new String();



        str +=",This will demonstrate the reverse function.";

        //Create a object of String Buffer class
        StringBuffer strbuf= new StringBuffer();
        strbuf.append(str);
        System.out.println(strbuf);
        strbuf.delete(0,str.length());

        //reverse()
        strbuf.reverse();
        System.out.print("Reversed string : ");
        System.out.println(strbuf);
        strbuf.reverse();
        System.out.println(strbuf);
        }
        catch(StringIndexOutOfBoundsException e){
              System.out.println(e.getMessage());

    }   
    }
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

1. Read the forum rules.
2. Read how to use code tags in the sticky
3. Explain what your code is meant to do, what it does, a description of what exactly you need help with, and where you think the problem is.

Thanks. Regretfully I am way too tired to redo it tonight. I will work on it more tomorrow. Sorry about the code tags. And yes I am a student just trying to get a grasp on Java, but not in any hurry. Thanks.

I went a different route and got it. But thanks I appreciate the help.

/This program uses String Builder because it already has 
//a reverse method in it. 
//Debi Justus
//This program also uses the JoptionPanel. 
//This program also uses two nested loops

import javax.swing.*;

public class Reverse {
    public static void main(String[] args) {

        String input;    // Used for the input string.

        String reversed; // Reversed form or the input string.


//The while loop is the outer loop

        while (true) {
            input = JOptionPane.showInputDialog(null, "Enter a name or sentance, I will reverse it");
            if (input == null) break;


            //The program will reverse the String input


            reversed = "";

            //The nested for loop reads the input String

            for (int i=0; i<input.length(); i++) {
                reversed = input.substring(i, i+1) + reversed;
            }

            //Display the Results

            JOptionPane.showMessageDialog(null, "Reversed:\n" + reversed);
        }
    }
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.