AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



java-programming: Write a java program to display the days in a week

write a program in java to display days in a week using multiple selection.

java x 210
programming x 165
Posted On : 2014-07-07 16:31:03.0
profile prince haxor - anyforum.in prince haxor
1930
up-rate
-3
down-rate

Answers


Hey what do you mean by multiple selection. kindly describe all your requirements in a more specific way about what do you want from your program with a sample i/p and o/p. Mention all the things by replying on my thread.

Posted On : 2014-07-07 17:24:36
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523186220581
Reply This Thread
up-rate
1
down-rate

Following is the java program to print the days of a week.


DisplayDays.java:
----------------------------------

public class DisplayDays {
public static void main(String[] args){

//Initialize array
int[] daysArray = {1, 2, 3, 4, 5, 6, 7};

//Loop through array
for(int i = 0; i < daysArray.length; i++){
//Get day
int day = daysArray[i];

//Switch-case structure
switch(day){
case 1: System.out.println(day + " = Sunday"); break;
case 2: System.out.println(day + " = Monday"); break;
case 3: System.out.println(day + " = Tuesday"); break;
case 4: System.out.println(day + " = Wednesday"); break;
case 5: System.out.println(day + " = Thursday"); break;
case 6: System.out.println(day + " = Friday"); break;
case 7: System.out.println(day + " = Saturday"); break;
default:;
}
}

}
}

/******************************* Output *********************************/
1 = Sunday
2 = Monday
3 = Tuesday
4 = Wednesday
5 = Thursday
6 = Friday
7 = Saturday

As we have used a for loop to print all the days of a week. At each time one case statement is executed. You can also do it by user input. when user press 1 , case 1 will be executed and Sunday will be printed.

Posted On : 2014-07-09 22:56:54
Satisfied : 1 Yes  0 No
profile Garima Gupta - anyforum.in Garima Gupta
596128524353
Reply This Thread
up-rate
4
down-rate

Wow! thank alot bro....

Posted On : 2014-07-10 20:04:53
Satisfied : 1 Yes  0 No
profile prince haxor - anyforum.in prince haxor
1930
Reply This Thread
up-rate
0
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in