ok, so i know this is stupid and probably the easiest thing in java but my brain is not working right now. so i'll ask, how do you add the numbers after you divide them in a for loop. for example:
i ask a user to enter a number, the program will then divide the number into half each time it iterate upto 5 times and then at the end it will add them all together.
For example, the user enters 5. The loop would add (5+2.5+1.25+0.625+0.3125) over the course of all iterations and then print out 9.6875
here's my code:
import java.util.Scanner;
public static void main(String[] args) {
Scanner Keyboard = new Scanner(System.in);
System.out.print("Please enter your number: ");
double userNum = Keyboard.nextDouble();
double total = 0.0;
for(int i = 0; i <= 4; i++){ //runs the loop
userNum = (userNum/2.0); // divides user number by 2 each time it runs through the loop
System.out.println(userNum + userNum); //prints the number and its subsequent reults
}
it does the division just fine but how do i add integers together??
thanks