So when i go to compile my lab it says that PrintSum(num) the num is not initialized, but it shouldn't be because i'm using num to call a method. this is part of my program, if you can tell me what it's saying that, that would be great. I'm sure it's an easy fix and im just thinking too much into it.
if(fileOpened&&inputFile.hasNext()){
while(inputFile.hasNext()){
if(inputFile.hasNextInt()){
PrintSum(num);
System.out.println("The sum of digits is " +PrintSum(num));
}
else
inputFile.next();
}
}
}
//method to print sum of 2 digits
public static int PrintSum(int number){
int result=0;
while(number!=0){
result=result+(number%10);
number=number/10;
}
return result;
}
int num;useint num = 0;(nummust have a value before any access to its value occurs).