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.

http://img14.imageshack.us/img14/7605/asdasdasdby.png

To see how to generate the output you want, replace the text in the output with the indexes for that text.
For example the indexes for output first shown is: 1,0 2,0 3,0 ...
You could generate the above output by printing the indexes vs the contents of the array at those indexes.
When you lay out the indexes for the way you want the output to look, then you should be able to change the loops to output the text in that order.

i asked three questions...which question u answered ? is it 3rd ?

I Want the Output to be:

This one.

Is it possible to loop through the Arrays instead of writing every row in new line ?

I didn't understand this one. Can you show the array and the desired output.

is it possible to print it in a table with different values for each days?

Yes. I assume you mean you want to change the contents of the columns that print beneath the header line that has the days.
One way would be to have an array with the data to print in each column and on each row.

is it possible to store different values for each row ??

Yes.

here is what i'm asking in 2nd question...

DnP [1] = Periods.Period1.name();
DnP [2] = Periods.Period2.name();
DnP [3] = Periods.Period3.name();
DnP [4] = Periods.Period4.name();
DnP [5] = Periods.Period5.name();


Instead of writing all rows in new line can i do this in a single line using loop ?
I mean can i assign a single variable for the rows 1,2,3,4,5 ??
like this

for (int k=1; k<=5; k++){
for (int i=0; i<=4; i++)
{
DnP [[B]k[/B]] = Periods.Period1.name();
}

????

But i don't kn0w how to lo0p through Enum of Periods...? i.e Periods.Period1.name();

To see how to generate the output you want, replace the text in the output with the indexes for that text.
For example the indexes for output first shown is: 1,0 2,0 3,0 ...
You could generate the above output by printing the indexes vs the contents of the array at those indexes.
When you lay out the indexes for the way you want the output to look, then you should be able to change the loops to output the text in that order.

I didn't get your answer ??
i want to write the code for output in one line instead of writing a separate line for each row

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.