Results 1 to 2 of 2
  1. #1
    trump101 is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default Stuck on code...plz help

    So wat i can't figure out is how to take the following code that i wrote and put the output which i get into an array? Here's my code

    import javax.swing.*;

    import java.util.Date;

    public class word{

    public static void main (String [] args) {

    //Declaring variables

    String s;
    char firstLetter; //first random consonant
    char secondLetter; //random vowel
    char thirdLetter; //second random consonant


    for (int i=0; i<=9;i++){

    firstLetter=chooseConsonant();
    secondLetter=chooseVowel();
    thirdLetter=chooseConsonant();





    System.out.println("Input was: "+" "+firstLetter+secondLetter+thirdLetter);
    }

    }








    public static char chooseConsonant() {

    final String CONSONANTS = "bcdfghjklmnpqrstvwxyz";

    return CONSONANTS.charAt((int)(Math.random()*CONSONANTS.l ength()));
    }

    public static char chooseVowel(){

    final String VOWELS="aeiou";

    return VOWELS.charAt((int)(Math.random()*VOWELS.length()) );
    }

    }

  2. #2
    trump101 is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default

    So i figured out how the print it to an array so my code now looks as follows, but now what i'm having trouble with is how to get the user to enter a "rank" from 0-9 in regards to the original string...and then finally print the array of 10words in order of rank....

    Java Code:
    import javax.swing.*;
    
    import java.util.Date;
    
    public class word{
    
    	public static void main (String [] args) {
    
    		//Declaring variables
    
    		String s;			//stores the original random 3-letter words
    		char firstLetter;	//first random consonant
    		char secondLetter;	//random vowel
    		char thirdLetter;	//second random consonant
    
    
    		for (int i=0; i<=9;i++){
    
    		firstLetter=chooseConsonant();
    		secondLetter=chooseVowel();
    		thirdLetter=chooseConsonant();
    
    
    		//this array stores the 10 random 3-letter words
    		char myarray[] = {firstLetter, secondLetter, thirdLetter};
    	 	s = String.valueOf(myarray);
    
    
    
    
    
    		//Prints out the original array of 10 3-letter words
    		System.out.println(myarray);
    		}//closes for loop
    
    
    
    
    	}
    
    
    
    
    
    		public static char chooseConsonant() {
    
    			final String CONSONANTS = "bcdfghjklmnpqrstvwxyz";
    
    			return CONSONANTS.charAt((int)(Math.random()*CONSONANTS.length()));
    		}
    
    
    
    		public static char chooseVowel(){
    
    			final String VOWELS="aeiou";
    
    			return VOWELS.charAt((int)(Math.random()*VOWELS.length()));
    		}
    
    	}//closes main

Similar Threads

  1. really stuck now..
    By shongo in forum Advanced Java
    Replies: 2
    Last Post: 11-09-2008, 02:56 AM
  2. Stuck in need of help!
    By Zombie_Leg! in forum New To Java
    Replies: 1
    Last Post: 09-23-2008, 02:22 AM
  3. [SOLVED] Using Code Throughout 5 Classes-Stuck
    By Bascotie in forum New To Java
    Replies: 46
    Last Post: 06-06-2008, 05:51 AM
  4. musically stuck
    By geork in forum New To Java
    Replies: 1
    Last Post: 02-06-2008, 09:44 PM
  5. Replies: 3
    Last Post: 12-05-2007, 02:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •