I want to input 10 marks for subjects from user.
and want print
- total
- max
- min
- average
I found total & max using this code
import java.util.Scanner;
class Example{
public static void main(String args[]){
Scanner input=new Scanner(System.in);
int tot=0;
int max=0;
int min=0;
double avg=0;
for(int i =1;i<=10;i++){
System.out.print("Input subject "+i+" marks : ");
int marks=input.nextInt();
tot+=marks;
if(marks>max)
max=marks;
}
System.out.println(tot);
System.out.println(max);
System.out.println(min); //want to find
System.out.println(avg); //want to find
} }
Now I want to find min & average of marks using loops and if else (is it possible?). How to find them?
Aucun commentaire:
Enregistrer un commentaire