Answered # how to divide in java

rubberman 1,109 JamesCherrill 2,785 Discussion Starter divinity02 6 JamesCherrill 2,785 I'm working in Excel to extract content of a table from a web page and populate Excel sheet cells with it. I'm trying to extract data from a table that gets loaded to a web page after show results method gets called. I have an error that says "Run-time error ...

0

float x = 10.0;

float y = 2.0;

float z = x/y;

System.out.printf("x == %f, y == %f, x/y == %f\n", x, y , z);

0

If x is exactly divisible by y then that means x modulo y must be zero (ie the remainder is zero). Java uses the % operator for modulo

0

hello james, rubberman, stultuske

I am trying to get the last round of this game to generate random numbers from 1 to 25 and the second random numbers to generate from 2 to 9 and of which the first number must be divisible by the second numbers.

i am wondering if the codes that i have created will be able to do just as the question ask.

note that: I haven't finished coding as yet

here is the codes that I have created so far.

```
for(i = 9; i<=10; i++)
{
rand = 1 + randobj.nextInt(25);
rand2 = 2 + randobj.nextInt(8);
correctans = rand / rand2;
incorrectans = 25 + randobj.nextInt(59);
while(num1 %2 != 0) would this work
{
if(num1 % num2 !=0)this also, will it work or do i have it wrong
{
}
}
System.out.println(playername+"round 3"+ "level "+ i+ "question "+i+ "you are required to match the letter with the correct answer");
System.out.println(playername+" please divide "+ rand+ " / "+ rand2);
System.out.println("A:"+correctans);
System.out.println("B:"+ incorrectans);
choice = userinput.next().charAt(0);
```

0

generate random numbers from 1 to 25 and the second random numbers to generate from 2 to 9 and of which the first number must be divisible by the second numbers.

One approach is trial and error - easy to code but inefficient in execution (not a problem with these values, but does not scale well)

```
do
generate both random numbers
while (their modulo is not zero)
```

another way is to generate the second random number (2-9) and a random multiplyer (1- 25/firstnumber) . Mutliply those together to get the first number. This will always work first time.

This question has already been answered. Start a new discussion instead.

Recommended Articles

the function that I created to find the ...

When accessing from ######1.co.uk (which has an SSL) to document root ###/production everything works fine.

However when accessing ###/production from ######2.co.uk (which doesn't have an SSL - set up in the vhost file) the home page displays fine but the other pages are returning a 404.

Here's the entry in ...