Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9140025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:27:44+00:00 2026-06-17T09:27:44+00:00

I have an assignment/project to write a program that displays the integers between 1

  • 0

I have an assignment/project to write a program that displays the integers between 1 and 100 that are divisible by 6 or 7, but not both. It does not work the way I’ve written it below. Is my boolean value correct for what the question is asking?

import acm program.*;

public class SixAndSeven extends ConsoleProgram {
    public void run() {
        for (int n = 1; n < 100; n++) {
            boolean year = (n % 6 ==0) ||
                (n % 7 ==0) &&
                !(n % 6 == 0) &&
                ( n % 7 ==0);

             if (year) {
                 println(year);
             }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:27:44+00:00Added an answer on June 17, 2026 at 9:27 am

    You should do the below

    boolean year = ((n % 6 ==0) || (n % 7 ==0)) && !((n % 6 == 0) && ( n % 7 ==0));
    

    Basically group the 2 sets of conditions within a () before negating, so that the conditions apply correctly to both.

    To make it more readable, you could do this.. (though perhaps overkill..)

    boolean divisbleby6 = n%6 == 0;
    boolean divisbleby7 = n%7 == 0;
    boolean divisibleby6and7 = divisbleby6 && divisbleby7 ;
    
    boolean year = (divisbleby6 || divisbleby7) && !divisibleby6and7 ;
    

    or the clever method suggested by Mel (possibly harder to understand at a glance), which returns true only if one but not both conditions are true.

    boolean year = divisbleby6 != divisbleby7;
    

    P.S. Additionally, as user1333371 suggests, you probably want to do println(n);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assignment that wants me to write an ternary search algorithm and
I have an assignment for an ASP.NET project that deals with storing and retrieving
I have a question in my assignment / project that adds 1 to an
Thanks, for idea I have to write a procedure that computes number of project,
I have a C++ assignment and it specifies that I may not use .NET
I have an assignment about fftw and I was trying to write a small
I have an assignment to create a secure communication between 2 people with a
I have an assignment for school, and I'm not sure how the teacher wants
I was assigned the following project for my VB.Net programming course: Write a program
I have tables : Project table id name ------- 1 A 2 B Assignment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.