Professional Documents
Culture Documents
Methods in Java
1. Write following two java programs that capable to add and subtract given two numbers.
}
import java.util.*;
class Cal3
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int x ,y;
add(x,y);
sub(x,y);
}
import java.util.*;
class Cal4
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int x ,y;
int p = add(x,y);
int q = sub(x,y);
Write a java program which has two methods call findAverage() and findMax() to get the average mark and the
maximum mark out of all marks.
Array should be define in the main method and output should be produced at the main method.
Following algorithm can be used to find the maximum at the findMax() method
int max=m[0];
for (int i = 0; i < m.length; i++) {
if (m[i] > max)
max = m[i];
}
4. Write a java program to find circumference and area of a circle. Your program should be fulfill following
requirements.
Radius of the circle should be read in the main method of the program
Circumference and Area should be calculated at the circumference() and area() methods.
Circumference and Area should be displayed at the main method.
5. Write a Java program to store rainfall figures for 30 days for the month of June. You should save the
numbers in an array data structure.
a. Display the average rainfall figure for the month.
b. Display the sorted rainfall figures. (Use Arrays.sort(name of array))