Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
March 19th, 2013, 11:44 PM
 Life_Student
Contributing User

Join Date: Mar 2013
Posts: 41
Time spent in forums: 16 h 8 m 19 sec
Reputation Power: 1

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
March 20th, 2013, 12:16 AM
 Life_Student
Contributing User

Join Date: Mar 2013
Posts: 41
Time spent in forums: 16 h 8 m 19 sec
Reputation Power: 1
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
March 20th, 2013, 12:28 AM
 Life_Student
Contributing User

Join Date: Mar 2013
Posts: 41
Time spent in forums: 16 h 8 m 19 sec
Reputation Power: 1
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
March 20th, 2013, 01:46 AM
 Life_Student
Contributing User

Join Date: Mar 2013
Posts: 41
Time spent in forums: 16 h 8 m 19 sec
Reputation Power: 1
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
March 20th, 2013, 02:34 AM
 Life_Student
Contributing User

Join Date: Mar 2013
Posts: 41
Time spent in forums: 16 h 8 m 19 sec
Reputation Power: 1
I really need some help here Anyone!?!?!?!?!?!?!?

#6
March 20th, 2013, 04:39 AM
 Life_Student
Contributing User

Join Date: Mar 2013
Posts: 41
Time spent in forums: 16 h 8 m 19 sec
Reputation Power: 1

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");
}

}
}