JAVA
Posted: Tue Feb 03, 2004 4:53 pm
does anyone here know a bit about java, i'm having trouble using variables created inside a loop,
i'm using 2 loops to collect test and quiz grades, but if i try to do like
System.out.println(Test);
it cant find the $var Test, once i have collected all the grades, i need to do some math on them so calculate the final average
Code: Select all
import cs1.Keyboard;
public class Final
{
public static void main(Stringї]args)
{
int num1 = 3;
int num2 = 5;
int min = 0;
System.out.println("You will now enter 3 test grades,\nthen 5 quiz grades\nthen the students average will be outputed:");
while (num1!=min)
{
System.out.println("Please enter a test grades:");
int Test = Keyboard.readInt();
if ((Test<0) || (Test>100))
{
System.out.println("Please input a valid grade (greater than 0)");
}
if ((Test>0) && (Test<100))
{
num1--;
}
}
while (num2!=min)
{
System.out.println("Please enter a quiz grades:");
int quiz = Keyboard.readInt();
if ((quiz<0) || (quiz>100))
{
System.out.println("Please input a valid grade (greater than 0)");
}
if ((quiz>0) && (quiz<100))
{
num2--;
}
}
}
}System.out.println(Test);
it cant find the $var Test, once i have collected all the grades, i need to do some math on them so calculate the final average