Convert totalDays to months, weeks, and days, finding the maximum number of months, then weeks, then days. Ex: If the input is 251, then the output is: Months: 8 Weeks: 1 Days: 4 Note: Assume a month has 30 days. A week has 7 days. Scanner scnr = new Scanner(System.in); int totalDays; int numMonths; int numWeeks; int numDays; 5 6 7 8 9 PEAREDNEG 10 11 12 13 14 15 16 17 18 19} } totalDays scnr.nextInt(); *Your code goes here */ = System.out.println("Months: System.out.println("Weeks: System.out.println("Days: 11 "1 + numMonths); + numWeeks); + numDays);
Convert totalDays to months, weeks, and days, finding the maximum number of months, then weeks, then days. Ex: If the input is 251, then the output is: Months: 8 Weeks: 1 Days: 4 Note: Assume a month has 30 days. A week has 7 days. Scanner scnr = new Scanner(System.in); int totalDays; int numMonths; int numWeeks; int numDays; 5 6 7 8 9 PEAREDNEG 10 11 12 13 14 15 16 17 18 19} } totalDays scnr.nextInt(); *Your code goes here */ = System.out.println("Months: System.out.println("Weeks: System.out.println("Days: 11 "1 + numMonths); + numWeeks); + numDays);
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question

Transcribed Image Text:Jump to level
Convert totalDays to months, weeks, and days, finding the maximum number of months, then weeks, then days.
Ex: If the input is 251, then the output is:
Months: 8
Weeks: 1
Days: 4
Note: Assume a month has 30 days. A week has 7 days.
Scanner scnr = new Scanner(System.in);
int totalDays;
int numMonths;
int numWeeks;
int numDays;
56
7
8
9
10
11
12
13
14
15
16
17
18
19}
}
totalDays
scnr.nextInt();
* Your code goes here */
System.out.println("Months:
System.out.println("Weeks:
System.out.println("Days:
=
"1
"1
11
+ numMonths);
+ numWeeks);
+ numDays);
Expert Solution

Step 1finding th
Algorithm
- Start the program
- Declare the class name as "Main" and include the main method.
- Declare an object 'scnr' of the Scanner class to read input from the user.
- Read an integer input from the user and store it in a variable 'totalDays'.
- Declare and initialize the variables numMonths, remainingDays, numWeeks and numDays to count the months, weeks and days.
- Calculate the number of months by dividing the totalDays by 30 and store it in the numMonths variable.
- Calculate the remaining days by using the modulo operator(%) and store it in the remainingDays variable.
- Calculate the number of weeks by dividing the remainingDays by 7 and store it in the numWeeks variable.
- Calculate the number of days by using the modulo operator(%) and store it in the numDays variable.
- Print the value of months, weeks and days.
- End the program.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education