Question

Create a while loop that will execute the following code 12 times using a counter that starts at 1 and is incremented by 1 ea
In Java
0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class Example {
public static void main(String[] args) {
int i=1;
String s1="";
int count=0;
while(i<=12){
  
switch(i){
case 1: s1="January";
count=31;
break;
case 2: s1="Febuary";
count=28;
break;
case 3: s1="March";
count=31;
break;
case 4: s1="April";
count=30;
break;
case 5: s1="May";
count=31;
break;
case 6: s1="June";
count=30;
break;
case 7: s1="July";
count=31;
break;
case 8: s1="August";
count=30;
break;
case 9: s1="September";
count=31;
break;
case 10: s1="October";
count=31;
break;
case 11: s1="November";
count=30;
break;
case 12: s1="December";
count=31;
break;

}
System.out.print("Month:"+s1 + " "+"Day count=" + count);
System.out.print("\n");
++i;

}
}
}

Add a comment
Know the answer?
Add Answer to:
Create a while loop that will execute the following code 12 times using a counter that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a Book object using a Java program. This object should contain the following variables bookName,...

    Create a Book object using a Java program. This object should contain the following variables bookName, bookAuthorName, bookGenre. Now create 3 different book objects and store them in an array. Finally iterate through this array and print out the book names.

  • This question deals with extending already existing Java code via a while loop. Ask the user...

    This question deals with extending already existing Java code via a while loop. Ask the user how many year inputs he wants to check - an integer. Assume that the user always gives an input which is between 1 and 5 (inclusive). Next, ask the user for K number of year inputs where K = the number user has given as input before (inside a while loop). Check for each year input whether that year is a leap year or...

  • C++ Write a program that illustrates enumeration types. Define an enumeration type for the months of...

    C++ Write a program that illustrates enumeration types. Define an enumeration type for the months of the year. This should be global. Put it above the main program. Declare a variable of the enumerated type called month; Declare an array of unsigned integers called year[12] and initialize the array to the days in each month. (Just assume 28 for February.) 1. Write a loop that will progress from January through December printing out the days in each month. The index...

  • JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate...

    JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate passing array reference to a method;        III. Demonstrate creating array of objects that prints out only x 0.0 for all objects. PROJECT 5C - ARRAYS Create a new file called " EventArray5C". There are some "challenging" directions in this project. . 1.Prepare a document box (tell me that task(s) the application is to accomplish, how it will accomplish the tasks, the author of...

  • Please design, write the code and create the requisite submission files in C++ for the following...

    Please design, write the code and create the requisite submission files in C++ for the following problem: A menu-driven program that offers the user 5 options as follows: Menu: 1. Display array 2. Add up all elements in the array and display that number. 3. Add 1 to each element in the array. 4. Swap the values in row one with the values in row three. 5. Exit In main(), declare and initialize a 2-dimensional array that contains 5 x...

  • create case 4 do Method 1:copy item by item and skip the item you want to...

    create case 4 do Method 1:copy item by item and skip the item you want to delete after you are done, delete the old file and rename the new one to the old name. #include int main(void) { int counter; int choice; FILE *fp; char item[100]; while(1) { printf("Welcome to my shopping list\n\n"); printf("Main Menu:\n"); printf("1. Add to list\n"); printf("2. Print List\n"); printf("3. Delete List\n"); printf("4. Remove an item from the List\n"); printf("5. Exit\n\n"); scanf("%i", &choice); switch(choice) { case 1:...

  • Lab 3 Step One First, create an empty directory for lab3. There is no starter code for this lab. You will be throwing an...

    Lab 3 Step One First, create an empty directory for lab3. There is no starter code for this lab. You will be throwing and catching exceptions in this exercise. Create a file called RuntimeException.h and put the following code in it. #include <string> class RuntimeException { private: string errorMsg; public: RuntimeException(const string& err) { errorMsg = err; } string getMessage() const { return errorMsg; } } Step Two In a new .cpp file in your directory, write a main function...

  • I should use the array and loop to create a java program according to the instruction,...

    I should use the array and loop to create a java program according to the instruction, but I have no idea how to do it. Introduction This lab assignment continues to give you practice using loops, particularly loops with variable termination conditions, and it also provides you an opportunity to use one-dimensional arrays. Recall that an array is used to store a collection of data. The data can be values of Java primitive data types or else objects (for instance,...

  • Create a program using the Random class and While loops in Java. The program should generate...

    Create a program using the Random class and While loops in Java. The program should generate a random number from 50 through 100. The loop should add the five random numbers generated. On each iteration of the loop the program should print out the number generated, how many numbers have been generated thus far, and the sum so far. On the last iteration, the printout should say the The final total is.... Teach comment the last time I did it:...

  • I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt...

    I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt Project#3 is an extension of the concepts and tasks of Lab#3. You will again read the dictionary file and resize the array as needed to store the words. Project#3 will require you to update a frequency counter of word lengths every time a word is read from the dictionary into the wordList. When your program is finished this histogram array will contain the following:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT