See this Program,
class Test {
enum Days {Monday,Tuesday,Wednesday,Thursday,Friday}
enum Periods {Period1,Period2,Period3,Period4,Period5}
public static void main (String [] args)
{
String DnP [][] = new String [6][5];
for (Days dys : Days.values())
{
DnP [0][dys.ordinal()] = dys.name();
System.out.print (DnP[0][dys.ordinal()] + "\t ");
}
System.out.println ("\n\n");
for (int i=0; i<=4; i++)
{
DnP [1][i] = Periods.Period1.name();
DnP [2][i] = Periods.Period2.name();
DnP [3][i] = Periods.Period3.name();
DnP [4][i] = Periods.Period4.name();
DnP [5][i] = Periods.Period5.name();
System.out.print (DnP [1][i] + "\t " );
System.out.print (DnP [2][i] + "\t " );
System.out.print (DnP [3][i] + "\t " );
System.out.print (DnP [4][i] + "\t " );
System.out.print (DnP [5][i] + "\t " );
System.out.println ("");
}
}
}
The output of the program is:
Monday Tuesday Wednesday Thursday Friday
Period1 Period2 Period3 Period4 Period5
Period1 Period2 Period3 Period4 Period5
Period1 Period2 Period3 Period4 Period5
Period1 Period2 Period3 Period4 Period5
Period1 Period2 Period3 Period4 Period5
I Want the Output to be:
Monday Tuesday Wednesday Thursday Friday
Period1 Period1 Period1 Period1 Period1
Period2 Period2 Period2 Period2 Period2
Period3 Period3 Period3 Period3 Period3
Period4 Period4 Period4 Period4 Period4
Period5 Period5 Period5 Period5 Period5
I know this is happening because i have printed all the rows in a single loop, but i really don't know how to print them separately in a single loop so that it gives the desire output.
Now see this part of the code,
DnP [1][i] = Periods.Period1.name();
DnP [2][i] = Periods.Period2.name();
DnP [3][i] = Periods.Period3.name();
DnP [4][i] = Periods.Period4.name();
DnP [5][i] = Periods.Period5.name();
Is it possible to loop through the Arrays instead of writing every row in new line ?
I tried it but i didn't solve it because every row is storing Different enum values so i also have to loop through Enum values there but i dont know how to loop through enum values there ?
i mean i want to do this,
DnP [[B]any variable[/B]][i] = Periods.[B]-How to Loop There-[/B].name();
???
and the last question .....
is it possible to store different values for each row ??
Plesae see this
if i have Enum values like this
enum Days {Mon,Tues,Wed,Thus,Frid}
enum Periods {English,Electronics,Programming,AutoCAD,Physics}
is it possible to print it in a table with different values for each days?, for example we can print Periods on any positon we want.
see this image.