Because I used integer division, i.e 5/2 the result would have been 2. Rather than 2.5 using (double) is a cast, it casts the number to a double thus it can then output the real value of 2.5
You...
Type: Posts; User: Freaky Chris
Because I used integer division, i.e 5/2 the result would have been 2. Rather than 2.5 using (double) is a cast, it casts the number to a double thus it can then output the real value of 2.5
You...
You might say it's a bit "hacky" lol.
import java.util.Scanner;
public class Average {
public static void main(String[] args) {
int total = 0, i = 0;
for(int temp; (temp = new...
Just add all the number up that the user inputs, then divide them by the number of numbers they entered after your while loop.
Chris
if you change, while(i> -1) to while(i != -1) then you don't need the if statement.
Chris
Do while would certainly be better than a while loop in this case. I myself used a for loop.
Chris
You can do it in a number of ways, but for sure you will need loops.
Also you will need an if statement to check if the input is a -1. You can write this in one loop, and it would only be about 5...