0% found this document useful (0 votes)
36 views

Another Method Example

This document contains code that defines and calls methods across multiple classes to perform calculations. The main method calls the doubleit method, which doubles an input integer, and the same method, which calls doubleit and then halves the result. The doubleit method is defined to multiply the input by 2, and same calls doubleit before passing the result to the half method in another class to divide it by 2 and return an integer.

Uploaded by

Sujai Senthil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Another Method Example

This document contains code that defines and calls methods across multiple classes to perform calculations. The main method calls the doubleit method, which doubles an input integer, and the same method, which calls doubleit and then halves the result. The doubleit method is defined to multiply the input by 2, and same calls doubleit before passing the result to the half method in another class to divide it by 2 and return an integer.

Uploaded by

Sujai Senthil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Another Method Example

Main Program File:


public class Methods001 {
public static void main(String[] args) {
System.out.println(MyMath.doubleit(5));
System.out.println(MyMath.same(5));
}
}

MyMath.java:
public class MyMath {
public static int doubleit(int a){
return 2*a;
}
public static int same(int t){
int x = doubleit(t);
double y = MoreMath.half(x);
return (int)y;
}
}

MoreMath.java:
public class MoreMath {
public static double half(double x) {
return x / 2;
}
}

Run:
10
5

You might also like