1

I am taking an HTML / Web Design course and just started it the other week. Now this isn't the first time I've done HTML, but I don't really remember much of it. I am trying to put some Java Code onto one of my web pages, as a way of "showing my recent accomplishments".

So what I'm looking for is a way to format a block of text, so that it retains all its white space / tabs.

<BODY>
    <h1> Java Code Samples! </h1>

    <P> Hello, and welcome to the java code sample section of my site. Here I will put some </P>
    <P> random samples of code that I have written and projects that I have completed </P>
    <br />
    <h3 align="left"> These are some random methods: </h3>
    <p>
    <i> //Returns index of item in other array
        //Efficiency ( O(N) )
        public static int getOtherIndex(String searchString, College[] searchTarget)
        {
            for(int i = 0; i < searchTarget.length; i++)
                if(searchString.trim().equalsIgnoreCase(searchTarget[i].nameOfSchool.trim()))
                    return i;

            return -1;
        }
    </i>
    </p>

</BODY>

I am trying to format the method in a way that retains the initial white space, but while using the italics tag to make it stand out.

Any help would be appreciated.

1 Answer 1

1

You can use the <pre> tag to do this.

It keeps the formatting the same.

Example: http://jsfiddle.net/jasongennaro/JC9ej/

Fyi... better to style the p tag than to use an i for italics.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.