Page 247 - IT-802_class_12
P. 247
Notes
That the array must be sorted before invoking binarySearch(). If it is not sorted, the results are
undefined.
3.8 uSEr-dEFInEd mEthodS
Sometimes, we may come across certain problems which require executing some tasks repeatedly, but with different
input values. This is exactly the situation where we use user-defined methods.
Let us take an example.
Write a program in Java to print the sum and average of two marks 10 and 30 obtained by a student. Also, the same
operation is required to be done for the other student who got 20 and 35 marks.
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/project/maven2/JavaApp/src/
main/java/${packagepath}/${mainClassName}.java to edit this template
*/
package com.mycompany.sum_average;
/**
*
* @author orange
*/
class Sum_average
{
public static void main(String [] args)
{
int m1=10, m2=30, n1=20, n2=35, sum;
double avg;
sum = m1+m2;
Fundamentals of Java Programming 245

