How To Find Out Your Semester Average
Coffee Program To Calculate Average Marks | five Methods
Java program to summate the average of marks. Here we embrace five simple ways to detect out the average of marks in Coffee programming. If you know the basics of coding, you can fifty-fifty write more 5+ ways. All the same, as a newbie, nosotros share the programme in 5 dissimilar ways. Do check it out. Our database consists of more than than 100+ sample Coffee programs. The post-obit program is written in v simple ways: standard values, class, by using method, by using command line arguments.
Tabular array Of Contents:
So, How to calculate the boilerplate of marks in math?
A: That'due south quite simple, for example, consider you have just completed your sem exams, and the consequence announced every bit:
- Maths – 75
- Science – 55
- Operating Systems – 80
- Dataware house – 75
- Now, sum up all –285/iv = 71.25 ( Your boilerplate marks )
So, your average of entire subjects are = 71.25 ( Formula stated below)
That's a standard and the merely mode to calculate your boilerplate of marks. Now, bank check out the following programs.
Average Marks Java Programme Five Simple Ways
Example Code -1: ( using standard values )
- Bones version with standard values. Hither we took Int n=5; it's all up to you. And also check output screen.
ane 2 three 4 5 vi vii 8 9 10 eleven 12 xiii fourteen 15 sixteen 17 18 19 20 21 22 23 24 25 26 | class AverageMarks { public static void main ( String arg [ ] ) { int n = 5 , avg = 0 ; int a [ ] = new int [ n ] ; a [ 0 ] = ten ; a [ ane ] = xx ; a [ 2 ] = xxx ; a [ iii ] = 40 ; a [ 4 ] = 50 ; for ( int i = 0 ; i < n ; i ++ ) avg = avg + a [ i ] ; Organization . out . println ( "average of (" + a [ 0 ] + "," + a [ one ] + "," + a [ two ] + "," + a [ three ] + "," + a [ 4 ] + ") is =" + avg / n ) ; } } |
- OutPut :
average of ( 10 , xx , 30 , xl , 50 ) is = 30 |
Coffee Programme Calculate Average Marks Using Arrays
- Coffee code for obtaining an average of marks taking inputs through Scanner class. Here it is: #Inputs Through Scanner Form#
1 2 iii iv 5 6 seven eight nine 10 11 12 13 14 fifteen sixteen 17 xviii 19 20 21 22 23 24 25 26 27 28 29 thirty 31 32 33 34 35 36 37 38 39 | import java . util . Scanner ; class AverageMarks { public static void main ( String args [ ] ) { int i ; System . out . println ( "Enter number of subjects" ) ; Scanner sc = new Scanner ( Arrangement . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ northward ] ; double avg = 0 ; Organization . out . println ( "Enter marks" ) ; for ( i = 0 ; i < northward ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } for ( i = 0 ; i < due north ; i ++ ) { avg = avg + a [ i ] ; } System . out . print ( "Boilerplate of (" ) ; for ( i = 0 ; i < due north - ane ; i ++ ) { System . out . print ( a [ i ] + "," ) ; } System . out . println ( a [ i ] + ") =" + avg / n ) ; } } |
- Output:
For example purpose, nosotros have executed the above plan with iii different outputs equally given below. Y'all need to enter the total number of subjects that you need to calculate or find and followed by marks. The console will display the output every bit follows:
1 2 iii iv 5 6 seven 8 9 10 11 12 xiii xiv 15 16 17 eighteen 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | output : 1 Enter number of subjects vi Enter marks 100 90 80 70 threescore fifty Boilerplate marks of ( 100 , 90 , fourscore , 70 , threescore , 50 ) = 75.0 output : two Enter number of subjects vi Enter marks 75 87 79 89 77 60 Average marks of ( 75 , 87 , 79 , 89 , 77 , 60 ) = 77.83333333333333 output : 3 Enter number of subjects 5 Enter marks 50 50 50 l 51 Boilerplate marks of ( 50 , 50 , fifty , l , 51 ) = 50.2 |
Average Marks Using Control Line Arguments
- Here we are using command line arguments if you take no thought about command line arguments in java then bank check out that link. As like above, the inputs are taken through scanner class, whereas here inputs are taking through control line arguments.
1 2 3 four v half-dozen 7 8 9 10 eleven 12 thirteen 14 xv 16 17 18 19 20 21 22 23 24 25 | class AverageMarks { public static void primary ( String args [ ] ) { int i ; int north = args . length ; double avg = 0 ; for ( i = 0 ; i < n ; i ++ ) { avg = avg + Integer . parseInt ( args [ i ] ) ; } System . out . impress ( "Boilerplate marks of (" ) ; for ( i = 0 ; i < n - ane ; i ++ ) { Organisation . out . print ( args [ i ] + "," ) ; } Arrangement . out . println ( args [ i ] + ") =" + avg / north ) ; } } |
- Output :
This is how the actual output screen volition look akin, c:\users\goutham\desktop ( Don't consider this , because we are executed the above code on our organisation, and so we copied the output hither ). Output console may vary code to lawmaking.
output : ane C : \ Users \ goutham \ Desktop \ E > javac AverageMarks . java C : \ Users \ goutham \ Desktop \ E > coffee AverageMarks 2 100 50 Average marks of ( 2 , 100 , 50 ) = l.666666666666664 output : 2 C : \ Users \ goutham \ Desktop \ E > javac AverageMarks . java C : \ Users \ goutham \ Desktop \ East > java AverageMarks 100 ninety eighty 70 60 fifty Average marks of ( 100 , xc , lxxx , lxx , 60 , fifty ) = 75.0 |
Coffee Programme Average Marks Using Class
- Java plan for calculating an average of marks through creating a separate grade(AverageCalculation) and taking inputs through scanner class. Cheque out the code.
one two iii four 5 6 7 8 9 x xi 12 xiii 14 15 16 17 eighteen 19 xx 21 22 23 24 25 26 27 28 29 xxx 31 32 33 34 35 36 37 38 39 xl 41 42 43 44 45 46 47 | import coffee . util . Scanner ; course AverageCalculation { double avg = 0 ; AverageCalculation ( int a [ ] ) { for ( int i = 0 ; i < a . length ; i ++ ) { avg = avg + a [ i ] ; } } } class AverageMarks { public static void primary ( String args [ ] ) { int i ; Arrangement . out . println ( "Enter number of subjects" ) ; Scanner sc = new Scanner ( System . in ) ; int north = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; Arrangement . out . println ( "Enter marks" ) ; for ( i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } AverageCalculation c = new AverageCalculation ( a ) ; System . out . print ( "Boilerplate of (" ) ; for ( i = 0 ; i < n - 1 ; i ++ ) { Organization . out . print ( a [ i ] + "," ) ; } System . out . println ( a [ i ] + ") =" + c . avg / n ) ; } } |
- Output: ( two Sample outputs )
ane 2 3 four 5 6 7 8 9 10 eleven 12 13 xiv 15 16 17 18 xix 20 21 22 23 | Output : 1 Enter number of subjects five Enter marks fifty 50 65 45 14 Average of ( l , 50 , 65 , 45 , 14 ) = 44.viii Output : 2 Enter number of subjects six Enter marks 89 99 78 87 45 65 Average of ( 89 , 99 , 78 , 87 , 45 , 65 ) = 77.16666666666667 |
Using Method
- Java code for calculating the average of marks using a user-defined method
i 2 3 4 5 6 7 8 9 10 11 12 13 fourteen 15 xvi 17 18 19 twenty 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import java . util . Scanner ; class AverageMarks { public static void chief ( String args [ ] ) { int i ; Organisation . out . println ( "Enter number of subjects" ) ; Scanner sc = new Scanner ( Organization . in ) ; int due north = sc . nextInt ( ) ; int [ ] a = new int [ northward ] ; System . out . println ( "Enter marks" ) ; for ( i = 0 ; i < northward ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } double avg = averageCalculation ( a ) ; System . out . print ( "Average of (" ) ; for ( i = 0 ; i < n - 1 ; i ++ ) { System . out . print ( a [ i ] + "," ) ; } System . out . println ( a [ i ] + ") =" + avg / northward ) ; } static double averageCalculation ( int a [ ] ) { double sum = 0 ; for ( int i = 0 ; i < a . length ; i ++ ) { sum = sum + a [ i ] ; } return sum ; } } |
- Output:
i ii 3 4 5 6 seven 8 9 10 11 12 13 14 fifteen xvi 17 18 19 20 21 22 23 | output : 1 Enter number of subjects 6 Enter marks 100 90 80 seventy 60 51 Average of ( 100 , 90 , 80 , 70 , 60 , 51 ) = 75.16666666666667 output : 2 Enter number of subjects 6 Enter marks 78 87 45 65 42 50 Average of ( 78 , 87 , 45 , 65 , 42 , 50 ) = 61.166666666666664 |
Source: https://javatutoring.com/java-program-calculate-average-marks/
Posted by: santanafaccons.blogspot.com
0 Response to "How To Find Out Your Semester Average"
Post a Comment