Results 1 to 5 of 5
  1. #1
    pwnagebeef's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    151
    Reputation
    10
    Thanks
    19
    My Mood
    Relaxed

    What did i do wrong here in my code?

    I can't find out what i did wrong here, it keeps saying there is an error with the face.
    "System.out.println(face+"\t"+freq[face]);"


    Code:
    import java.util.Random;
    
    public class oranges {
    	public static void main(String[]args){
    		Random dice= new Random();
    		int freq[]=new int [7];
    		
    		for (int roll=1;roll<1000;roll++){
    			++freq[1+dice.nextInt(6)];
    		}
    		
    		System.out.println("face\tFrequency");
    		
    		for (int face=1;face<freq.length;face++);{
    			System.out.println(face+"\t"+freq[face]);
    	} 
    	}
    }

  2. #2
    Decieved-'s Avatar
    Join Date
    Apr 2011
    Gender
    male
    Posts
    121
    Reputation
    23
    Thanks
    271
    My Mood
    Lurking
    What is the \t supposed to be doing, never seen that

  3. #3
    Saltine's Avatar
    Join Date
    Jun 2011
    Gender
    male
    Posts
    493
    Reputation
    104
    Thanks
    629
    Quote Originally Posted by pwnagebeef View Post
    I can't find out what i did wrong here, it keeps saying there is an error with the face.
    "System.out.println(face+"\t"+freq[face]);"


    Code:
    import java.util.Random;
    
    public class oranges {
    	public static void main(String[]args){
    		Random dice= new Random();
    		int freq[]=new int [7];
    		
    		for (int roll=1;roll<1000;roll++){
    			++freq[1+dice.nextInt(6)];
    		}
    		
    		System.out.println("face\tFrequency");
    		
    		for (int face=1;face<freq.length;face++);{
    			System.out.println(face+"\t"+freq[face]);
    	} 
    	}
    }
    Could you post more detail on the error?
    Also, I am pretty sure that length should be referenced as length(), as it is a method.
    Quote Originally Posted by Decieved- View Post
    What is the \t supposed to be doing, never seen that
    "\t" is known as an escape sequence. These are used in Java and other languages to format strings. This one in particular is the equivalent of using the "Tab" key. Java would remove the white space if you did not use "\t".
    @Decieved-
    Last edited by Saltine; 10-16-2011 at 05:23 PM.

  4. #4
    Decieved-'s Avatar
    Join Date
    Apr 2011
    Gender
    male
    Posts
    121
    Reputation
    23
    Thanks
    271
    My Mood
    Lurking
    Okay^^ Thanks

  5. #5
    mountainjew's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Posts
    51
    Reputation
    10
    Thanks
    18
    My Mood
    Amused
    for (int face=1;face<freq.length;face++);{

    Remove the bolded symbol and it works fine. After the closing parenthesis, you do not have to use the semicolon.
    Last edited by mountainjew; 10-18-2011 at 08:22 PM.

  6. The Following User Says Thank You to mountainjew For This Useful Post:

    pwnagebeef (10-19-2011)

Similar Threads

  1. Help - What did i do wrong?
    By Mr.1337 in forum Combat Arms Mod Discussion
    Replies: 6
    Last Post: 08-14-2010, 01:56 PM
  2. Please help me ! What did i do wrong ?
    By muumimamma in forum Combat Arms Mod Discussion
    Replies: 0
    Last Post: 06-16-2010, 03:23 AM
  3. whats did i do wrong? do you understand what this means
    By Gourav2122 in forum Hardware & Software Support
    Replies: 17
    Last Post: 07-05-2008, 11:25 AM
  4. what did i do wrong?
    By mpghhackersrock123 in forum Visual Basic Programming
    Replies: 10
    Last Post: 10-11-2007, 04:35 PM
  5. What did I do wrong???
    By ltkort213 in forum WarRock - International Hacks
    Replies: 7
    Last Post: 06-11-2007, 08:50 AM