One week is 7 days. Please write a program to calculate how many weeks and days for 500 days. (Using JAVA)
read number of days (here, it’s 500) from console
Use if…else to make sure that your input is a positive number.
import java.util.Scanner; public class DaysToWeeks { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter total number of days: "); int days = in.nextInt(); if (days >= 0) { int weeks = days / 7; int remainingDays = days % 7; System.out.println(days + " days is " + weeks + " weeks and " + remainingDays + " days."); } else { System.out.println("Invalid. Days can not be negative!"); } } }
Get Answers For Free
Most questions answered within 1 hours.