Having some difficulties coming up with doing the following:
1. If number inputed is even, the next number wld be half of it. the output wld show the numbers until it reaches 1.
2. need to add something at the end to count the number of times it was halved.
so far i think i got the following
public static void main(String args[])
{
do
{
int x = inputInt("enter a number");
} while (x < 1);
for (int i = 2; i ? ??; i++)
if (x % 2 == 0)
x = x/ 2;
output(x);
im thinking that a for loop has to be used in order for the numbers to halve although im not certain of what i has to be.
some help wld be appreciated thx.
2007-09-26
02:39:31
·
5 answers
·
asked by
Shadow K
1
in
Computers & Internet
➔ Programming & Design
ahhhh lol not a stupid Qs at all....its just that i wanted some guidance to how to halve numbers....wanted to figure out myself to program so that if it is an even it wld just keep on halfing...and if its an odd + wtv then end at 1 .
hope that kinda made some sense lol
2007-09-26
03:56:31 ·
update #1