id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

inBothRanges


public boolean inBothRanges(int number)

Given a number, return true if it is in both of 2 overlapping ranges.
Range1: 0-100 AND Range2: 50-200.
Return false if it isn't.


public boolean inBothRanges(int number) {
  boolean inRange1 = false;
  if (0 <= number && number <= 100) {
    inRange1 = true;
  }

  boolean inRange2 = false;
  if (50 <= number && number <= 200) {
    inRange2 = true;
  }
  
  boolean inBothRanges = false;
  if (inRange1 && inRange2) {
    inBothRanges = true;
  }
  return inBothRanges;
}

inBothRanges(50) → true
inBothRanges(100) → true
inBothRanges(0) → false

...Save, Compile, Run (ctrl-enter)

public boolean inBothRanges(int number) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 1

Copyright Nick Parlante 2017 - privacy