I have a section of code in a programme I have:

long b;
if (show>1189&&<1189*2)
{
b=1;
}
else if (show>1189*2&&<1189*3)
{
b=2;
}
else if (show>1189*3&&<1189*4)
{
b=3;
}


The variable show is an already defined string which takes a number value. So I want to output the result of this equation. however this if statement could go on and on and rather than keep writing out if else I wondered if it was possible using a for loop to repeat the process of if statements so that I dont have to keep typing out if its greater than 1 thing and less than another the variable equal the number. so the last answer to an if statement would be 100.

So the very last if statement would be

else(show > 1189*100)
{
b=100
}

I dont know how clear what I am asking is so if you dont understand please say so and I will calrify as best as i can.

Well, your explanation is a little difficult to follow, but it sounds like int division by 1189 is all you are needing

// assuming that show is an int or long
b = show/1189;

Does that yield the result you are trying to achieve?

no its not. you see each calculation shows a different thing. okay the end result will be a JOptionpane which shows the precentage read of all the chapters and the number of times the whole book is read. The percentage read I have already done and you helped me with last time.Now once that percentage gets to 100% or more I want it to say 1 for the number of times the book is read. If the percentage is 200% or more I want it to say 2 chapters or more and so on up to 100. Now i realise this can be done in an if statement but I am wondering if it can be done in a for loop or a nested for loop quicker?

It still sounds like int division is all you need. Take a look at the following and run it yourself it you want to verify the result:

int totalChapters = 1189;
    int chaptersRead= 1100;
    int timesBookRead = chaptersRead / totalChapters;  // yields 0
    System.out.println("times read = "+timesBookRead);
    chaptersRead = 1200;
    timesBookRead = chaptersRead / totalChapters;  // yields 1
    System.out.println("times read = "+timesBookRead);
    chaptersRead = 1189*3+24;
    timesBookRead = chaptersRead / totalChapters;  // yields 3
    System.out.println("times read = "+timesBookRead);

dude thanks again. I am gonna find oout how to give you a rep point and give you 1 for all your help. you were right about the division. I am doing it in a JOptionpane thats the only difference. I will get back to you on if it worked or not.

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.