1. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
41
Rep Power
2

Hey guys im stuck I need to use a do while loop to count the time s it takes for 1 / 2 to equal .0001.

this is what I have so far:

public class Divide {
public static void main(String[] args) {
double count = 1;
double x=1f;
double y=2f;
double z;
do {

z= x/y;
System.out.println("Count is: " + count);
count++;
} while (z <=.0001);
}
}

not sure how to return the value to keep doing the division.
2. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
41
Rep Power
2

#### stuck

been playin around with this but cant get it to work properly heres my new code:

public class Divide {
public static void main(String[] args) {
double n=1;
double Total = returnVal(n);
System.out.println();
}
public static double returnVal(double x){
double value = 1;
double i = x;
while(value <=.0001);
value = value/2;
i++;
return value;

}
}
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
41
Rep Power
2

#### initial problem

this is the initial problem if that helps:

If you divide 1 by 2, you get 0.5. If you divide it again by 2, you get 0.25. Write a
program using “do…while” loop to calculate and output the number of times you have to
divide 1 by 2 to get a value less than one ten-thousands (0.0001).
4. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
41
Rep Power
2

#### ahhh

alright pretty sure im wasting my time since no one will help me but now im 5 hours in on this problem and this is what i have. it doesnt work but i dont know what else to do

public class Divide {
public static void main(String[] args) {
double n =1;
double Final=NumR(n);
System.out.println(Final);
}
public static double NumR(double z){
double x=2;
double i =z;
double total;

do{
total =i/x;
i++;
}
while(i >=.0001);

return i;
}}
5. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
41
Rep Power
2
I really need some help here Anyone!?!?!?!?!?!?!?
6. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
41
Rep Power
2

this is what I have now I believe it works please check

public class Divide {
public static void main(String[] args) {

double x = 1;
double count = 0;
double tempNum = x / 2;

while (tempNum > .0001){
tempNum = tempNum / 2;
count++;

System.out.println("The number " + x + " is divisible by two " + count + " times");
}

}
}