1. Void method with no return value:
public class Calculator {
public static void main(String[] args) {
Calculator casio=new Calculator();
casio.add();
}
public void add(){
return;
}
}
Output:
Explanation:
- display() method has void return type
- return; is used just to exit the method
- Since there is no print statement, nothing is displayed.
Output: Nothing is displayed
2. Mark Calculation Program:
public class Student {
public static void main(String[] args) {
Student marks=new Student();
int tot=marks.total(70,90,100,99,98);
System.out.println(tot);
int avg=marks.average(tot);
System.out.println(avg);
String gra=marks.grade(avg);
System.out.println(gra);
}
public int total(int no1,int no2,int no3,int no4,int no5){
int result=no1+no2+no3+no4+no5;
return result;
}
public int average(int total){
int result=total/5;
return result;
}
public String grade(int avg){
if(avg>=90){
return "A";
}
else if(avg >= 85){
return "B";
}
else if(avg >= 80){
return "C";
}
else if(avg >= 70){
return "D";
}
else if(avg >= 60){
return "E";
}
else{
return "F";
}
}
}
Output:


Top comments (0)