Is there a way to access the object "rec" after the for loop when I try to print out rec.report()?
(Report() is a method inside of the class BmiRecord that returns new calculated results).
for(int i=0; i<limit; i++)
{
int height = scanner.nextInt();
int weight = scanner.nextInt();
String name = scanner.nextLine();
BmiRecord rec = new BmiRecord(name, height, weight);
}
System.out.println(rec.report());
scope. google.com/… The workaround is to define the objectBmiRecord rec = nulloutside forforloop, then only assign it inside the loop. Then you can use it after the loop terminates