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 8548151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:25:42+00:00 2026-06-11T13:25:42+00:00

I have a range from a min to a maximum. I want to generate

  • 0

I have a range from a min to a maximum.
I want to generate a set of information via calculation for each of these values.
I want to output this information via print.

How do I generate this output given a loop will only output information for 1 value of the range at a time?

Programming experience – absolute beginner.

Here’s the code:
Basically, if the user enters 1, I output information for all values of min2.
else, I output only the set of min2 and their information whose probB is 1/2.
Also, can I just use min1 (which comes from user input) without assigning it to min2?

int prompt = Integer.parseInt(input);   // user input
int min2 = 0;
double probB = 0;
for (min2 = min1; min2 < max1; min2++) // for loop
{
  if (prompt==1){
    int R = 0;
    double Rlow = 0;
    double Rhigh = 0;
    R = (int) (Math.sqrt(2) + 1)*min2;
    Rlow = (Math.sqrt(2)+1)*min2+ 1;
    Rhigh = (Math.sqrt(2)+1)*min2;
    System.out.println(min2);
    System.out.print(""+Rlow+""+Rhigh);
    System.out.println(R);
    probB = (R/R+min2)*(R-1/R+min2-1);
    System.out.println(probB);
  }
  else {
    int R = 0;
    double Rlow = 0;
    double Rhigh = 0;
    R = (int) (Math.sqrt(2) + 1)*min2;
    Rlow = (Math.sqrt(2)+1)*min2+ 1;
    Rhigh = (Math.sqrt(2)+1)*min2;
    probB = (R/R+min2)*(R-1/R+min2-1);

    if (probB == 1/2){
      System.out.println(min2);
      System.out.println(""+Rlow+""+Rhigh);
      System.out.println(R);
      System.out.println(probB);
    }
  }
}
  • 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-11T13:25:43+00:00Added an answer on June 11, 2026 at 1:25 pm

    Instead of

        if (probB == 1/2){
    

    use

        if (probB == 1.0d/2.0d){
    

    the expression 1/2 is calculated as an integer, and its value is zero. Even better:

        if (probB == 0.5d){
    

    Note however that if there’s any rounding in the calculation of probB the result might not end up being exactly 0.5 even when you expect it to. You can construct expressions where the end result ‘should’ be 0.5 but the actual result is very close to but not exactly 0.5, due to inaccuracies in floating point representations. Your best bet is to do something like:

        if (Math.abs(probB-0.5d) <1.0e-10d)
    

    I.e. close to one part in 10^10

    Floating point calculations are very useful, but they come with some gotchas due to the fact that they’re not exact representations. In decimal, there’s a whole set of rational numbers that cannot be expressed exactly, such as 1/3, 1/7, etc. You can get arbitrarily close by extending the number of digits (0.33333333… or 0.142857142857142…) but you can’t write an exact representation in decimal. The same thing happens in floating point (for a different set of numbers), but FP has a fixed length, so a number like 0.1 cannot be expressed exactly in FP. It’s close, but not exact. You must always allow for that possibility in comparisons.

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

Sidebar

Related Questions

Suppose I have range from E2 to E16. How do I read values from
I want to show continuous integer values from a certain min value to max
Assume I have a UISlider representing a continuous range of values from -1 to
right now I have min, max value from table1 that defines the range of
Specific instance of Problem I have an int range from 1-100. I want to
I have range of numbers that range from 1 - 0.00000X . Most are
I have an List<int> which contains 1,2,4,7,9 for example. I have a range from
I have a range of weekly variables describing a person's status (from week 1,
I have a query limited by a date range: select * from mytable where
I have the following to send an email, with a range of cells from

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.