r/learnjava • u/Icy_Ad871 • Feb 15 '21
I am having problems with this for
package For;
import java.util.Scanner;
public class lulatpreg3
{
/**
* @param args
*/
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.println("Enter grade of student number 1");
double grade = input.nextDouble();
double minave,ave;
minave = 0;
for (int i=1;i<3;i++){
int studentnum = 1;
double totalgrade = 0;
while (grade>=0){
totalgrade=totalgrade+grade;
grade = input.nextDouble();
studentnum++;
}
ave = totalgrade/studentnum;
if (ave>minave){
minave = ave;
}
}
System.out.println(minave);
}
}4
u/NautiHooker Feb 15 '21
Well, if you explain what kind of problems then you might receive help.
Describe what you want to achieve and what does not work. If you have error messages then show them.
Please edit your post.
1
u/Icy_Ad871 Feb 15 '21
Its supposed to receive the grades of three diferent classes and give the lowest average grade, but it doesnt do that.
1
u/nagarjuna_reddy_27 Feb 15 '21
Could you edit the post and keep the original question for that program?
1
0
u/GSD_101 Feb 15 '21
while (grade>=0){
totalgrade=totalgrade+grade;
grade = input.nextDouble();
studentnum++;
}so you are trying to take input in repetition with it?
if yes , put this line in loop and not at start..
System.out.println("Enter grade of student number 1");
double grade = input.nextDouble();Since you know its 3 classes , no need to set counter.
do away with while statement.
but before you try this
what do do you mean by minimum average of 3 classes.
Cuz you should use loop to get inputs and sum them and outside the loop get average.
4
u/[deleted] Feb 15 '21
What exactly is the problem you're having?