What did i do wrong here in my code?

Posts 15 of 5 · Page 1 of 1
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]);
	} 
	}
}
What is the \t supposed to be doing, never seen that
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-
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.
Posts 15 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?