hello,
i want to write a program that store subjects and days in two enumerations and their values in rows and coloumn using 2D array. how can i do this ?
class EnumProg {
enum Days {Monday, Tuesday, Wednesday, Thursday, Friday}
enum Periods {Period1, Period2, Period3, Period4, Period5}
public static void main (String [] args)
{
String [][] Timetable2A;
Timetable2A = new String [Days.Monday.ordinal()][Periods.Period1.ordinal()];
}
}
i really dont know how to use enumeration and arrays together and how to store values in arrays..i don't have any example program thorugh which i can learn this.
It is not printing in table, bcz u have used println() method instead of print() method in the second for loop.
The println() prints a newline after the contents, hence u r not getting in tabular form.
String daysPrds [][] = new String[6][5];
for(Days day : Days.values()) {
daysPrds[0][day.ordinal()] = day.name();
}
Days dys[] = Days.values();
for(Periods prds : Periods.values()) {
for( int i = 1; i<=dys.length;i++) {
daysPrds[i][prds.ordinal()] = prds.name();
}
}
for(int i = 0; i<daysPrds.length;i++) {
for(int j = 0; j<daysPrds[i].length; j++) {
System.out.print(daysPrds[i][j]+"\t");
}
System.out.println();
}
It is not printing in table, bcz u have used println() method instead of print() method in the second for loop.
The println() prints a newline after the contents, hence u r not getting in tabular form.