Search:

Type: Posts; User: Freaky Chris

Search: Search took 0.14 seconds.

  1. Re: Would You Use Loops and If/Else for This?

    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...
  2. Re: Would You Use Loops and If/Else for This?

    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...
  3. Re: Would You Use Loops and If/Else for This?

    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
  4. Re: Would You Use Loops and If/Else for This?

    if you change, while(i> -1) to while(i != -1) then you don't need the if statement.

    Chris
  5. Re: Would You Use Loops and If/Else for This?

    Do while would certainly be better than a while loop in this case. I myself used a for loop.

    Chris
  6. Re: Would You Use Loops and If/Else for This?

    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...
Results 1 to 6 of 6