Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
How do I keep track of a number in java?
It is in a loop that multiplies the number by 2. I need to know how to keep track of each result.
For example, if I enter 5, I want it to keep and display the number 10, 20, 40, 80.. etc. All in one line outside the loop.
1 Answer
- deonejuanLv 710 years agoFavorite Answer
public class TrackTwos {
public static void main( String[] args ) {
String accumulator = "";
int multiple = 5;
for( int i = 0; i < 40; i++ ) {
multiple *= 2;
accumulator += multiple + ",";
}
System.out.println( multiple );
}
}