Back to articles
Methods in Java

Methods in Java

via Dev.toSasireka

1) Void Method (No Return Value) public class Home { public static void main ( String [] args ){ Home obj = new Home (); obj . display (); } public void display (){ return ; } } 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) Marks Calculation Program public class Marks { public static void main ( String [] args ){ Marks obj = new Marks (); int total = obj . SumMarks ( 70 , 80 , 67 , 54 , 91 ); int average = obj . AvgMarks ( total , 5 ); obj . Grade ( average ); } public int SumMarks ( int no1 , int no2 , int no3 , int no4 , int no5 ){ return no1 + no2 + no3 + no4 + no5 ; } public int AvgMarks ( int no1 , int no2 ){ return no1 / no2 ; } public void Grade ( int no1 ){ if ( no1 > 90 ){ System . out . println ( "A Grade" ); } else if ( no1 > 80 ){ System . out . println ( "B Grade" ); } else if ( no1 > 70 ){ System . out . println ( "C Grade" ); } else { Syst

Continue reading on Dev.to

Opens in a new tab

Read Full Article
2 views

Related Articles