Hey guys! I've created a simple program that given the current day and how many days from the current day, it will determine if it's a Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, where 1 Sun, 2 -Mon, 3-Tues, 4 -Wed, 5 -Thurs, 6 -Fri, 7-Sat

My problem is that when I input two digits that when added is divisible by 7, the modulo will be 0. How do I fix that? For example: Inputting 5 as current day(Thursday) and 2 as days to go, the output will become 0. The output is supposed to be 7 for Saturday.

import java.util.Scanner;

public class Day
{

	public static void main (String[] args)
	{
		Scanner in = new Scanner (System.in);
		int nDayToday, nDaysToGo, nResult;
		
		System.out.print("Enter day today(1 Sun, 2 -Mon, 3-Tues, 4 -Wed, 5 -Thurs, 6 -Fri, 7-Sat): ");
		nDayToday = in.nextInt();
		System.out.print("Enter days to go: ");
		nDaysToGo = in.nextInt(); 
			
		nResult = (nDayToday + nDaysToGo) % 7;
		System.out.println(nResult);
	}
}

Recommended Answers

All 2 Replies

Simple.

Place a IF condition.

if(nResult==0)
      nResult=7;      //definitely it is saturday

Start from 0 for Sunday....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.