Tuesday, 29 August 2017

Java programming tutorial to calculate percentage marks of the student using else-if

Java program that calculate percentage marks of the student using else-if

Program

class Student {
public static void main(String args[])
{
if(args != null && args.length == 6)
{       
int s1 = Integer.parseInt(args[0]);
int s2 = Integer.parseInt(args[1]);
int s3 = Integer.parseInt(args[2]);
int s4 = Integer.parseInt(args[3]);
int s5 = Integer.parseInt(args[4]);
int s6 = Integer.parseInt(args[5]);
int ans=s1+s2+s3+s4+s5+s6/args.length;

System.out.println("Student 6 sub avg = " + ans);
System.out.print("Gread is : ");
if(ans>=90)
System.out.println("A");
else if(ans>=80)
System.out.println("B");
else if(ans>=70)
System.out.println("C");
else if(ans>=60)
System.out.println("D");
else
System.out.println("Fail");

}
else{
System.out.println("Wrong number of command line arguments. This program require 6 arguments");
}
}

}

Output

calculate percentage Java

0 comments:

Post a Comment