The Wulf
- Home
- StormHaven
- Journal
- Writings NEW
- About Me
- Java Scripts
- Video Game Class
- English Essay
- English Essay 2
Site
- DrabblesNEW
- SCA Novice Pic
- Links
- Quotes - broke
- Myrddin Keep
- Whois Script
- Hello World
- Kethryn
- Disclaimer
Poems
- America NEW
- Once More
- Moments
- Ask Me
- Death's Lover
- Leaving
- One Phone Call
- Dying
- If Only Published
- Where I Stand
- Tired
- Honesty
- Hate
- To Know Me
- Understand
- You Called
- I Couldn't
- Last Call
- Nature's Course
- Forever
- The Shadow Within
- Puddle of Dejection
- Duality of Love
Contact
- Email - broke
- Message Board - broke
- Joke of the Day
- A Day in Hell
- Guestbook - broke



Demonstrating how to print in Java.

StringFun
Tuesday, April 15, 2003, 2002
By Wulf

Untitled Document

/* Programmer          : Amanda                   */
/* User ID             : abc                         */
/* Section             : 6                                */
/* Assignment          : Program 3                        */
/* Due Date            : 03/18/03                         */
/* Purpose             : To print a user entered sentance and
the various mutations on it. */

import javax.swing.JOptionPane;

public class StringFun

    {

	public static void main (String args[])

    	    {
	
		/* Printing out personal information */
		System.out.println("Programmner           : Amanda");
		System.out.println("User ID               : abc ");
		System.out.println("Section               : 6 ");
		System.out.println("Program               : 3 ");
		System.out.println("Purpose               : Using String Methods.");
	
						
		/* Get a sentance from the user. */

		String phrase =JOptionPane.showInputDialog("Enter a Sentance");
      		String mutation1, mutation2, mutation3, mutation5;
		int mutation4;
		
		/* Make the various changes to the sentance. */

		mutation1 = phrase.toUpperCase();
		mutation2 = mutation1.toLowerCase();
		mutation3 = phrase.substring(0,5);                                              
		mutation4 = phrase.indexOf("a"); 
		mutation5 = phrase.replace('a','x');

		/* Print out each changed string. */
		System.out.println(" \nThe following is your sentance in uppercase lettering:");
		System.out.println(mutation1);
	
		System.out.println(" \nThe following is your sentance in lowercase lettering:");
		System.out.println(mutation2);		

		System.out.println(" \nThe following is the first five letters of your
		sentance:");
		System.out.println(mutation3);

		System.out.println(" \nThe first instance of the letter 'a' in your sentance
		is at index " + mutation4);
		
		System.out.println(" \nThe following is your sentance where the program changed
		'a' to 'x':");
		System.out.println(mutation5);

		System.out.println(" \nYour sentance consists of " + phrase.length() + "
		characters.");
	
		System.exit(0);
		
	}

}
Output

If the user input the following sentance - There is a green frog in my house thanks to the cat. 

Programmner           : Amanda
User ID               : abc
Section               : 6
Program               : 3
Purpose               : Using String Methods.

The following is your sentance in uppercase lettering:
THERE IS A GREEN FROG IN MY HOUSE THANKS TO THE CAT.

The following is your sentance in lowercase lettering:
there is a green frog in my house thanks to the cat.

The following is the first five letters of your sentance:
There

The first instance of the letter 'a' in your sentance is at index 9

The following is your sentance where the program changed 'a' to 'x':
There is x green frog in my house thxnks to the cxt.

Your sentance consists of 52 characters.