This is a simple project that i was using to test my current java knowledge (kinda like revision) and for that i used two classes to make a simple averaging program. i know i0m making it more difficult but like i said i'm testing myself but i come up with an unexpected error. Here's the code:
- 1st Class
import java.util.Scanner; public class Main { public static int num; public static int total = 0; public static int average; public static void main(String args[]) { Scanner scanner = new Scanner(System.in); Secondary secondaryObject = new Secondary(); secondaryObject.loop(num, total, scanner); average = total/3; System.out.println("Average: " + average); } }
- 2nd Class
import java.util.Scanner; public class Secondary { public void loop(int num, int total, Scanner scanner) { int counter = 0; while(counter < 3) { num = scanner.nextInt(); total += num; counter++; } } }
Now the problem is after inputing the numbers it doesn't give me the average but the value of 0. Althought this is not that big of a deal that just made me want to know why and if you could tell me that would be much appreciated.