What is the \t supposed to be doing, never seen that
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
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.
"\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.
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.
pwnagebeef (10-19-2011)