|
Post by JJHatton on Dec 15, 2013 16:44:43 GMT
I am extremely new to java coding and I'm following an 80+ video guide. (Currently on #20).
In one of the tutorials, it showed me how to make a very basic averagererer. E.g. You enter 10 numbers and it finds the average. I decided to change it a bit and allow the user to enter how many numbers he was averaging, instead of just ten.
This is the code:
import java.util.Scanner;
class apples{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int total = 0;
int grade;
int average;
int counter = 0;
int amount;
System.out.println("How many grades are there? ");
amount = input.nextInt();
while (counter < amount){
grade = input.nextInt();
total = total + grade;
counter++;
}
average = total/amount;
System.out.println("Your average is: " + average);
}
} I'm sure that some java veteran is going to laugh at me, I don't blame you. I just reallllllly want to get the hang of this shit.
The bit that eclipse says is a problem is:
System.out.println("How many grades are there? ");
amount = input.nextLine();
Because apparently input.nextInt doesn't work.... I have no freaking clue why.
|
|
|
Post by JJHatton on Dec 15, 2013 16:48:37 GMT
Oh my fucking God... I literally figured it out as I posted this. I forgot the "System.out.println("Now Type Your Grades!") bit so I kept thinking that the "int amount" was counting towards the "int grade"
|
|
|
Post by Rcon on Jan 10, 2014 12:22:37 GMT
Damnit, the one time my Java experience could've been used.
|
|