Java Method Practice Questions for Beginners
Java Method Practice Questions for Beginners
Beginners
Basic Method Practice
Write a method that takes two numbers and returns their sum.
Create a method that takes a number and returns `true` if it is even, else `false`.
Write a method to calculate the factorial of a number.
Create a method to check if a number is prime.
Write a method that returns the maximum of three numbers.
Method Overloading
Write overloaded methods for addition: one that adds two integers and another that
adds two doubles.
Create overloaded methods to calculate area: one for a circle, another for a rectangle.
Write a class with two `greet()` methods — one with no parameters and one with a
name.
Multiples of 10 stored in an Array
import java.util.Scanner;// Use this editor to write, compile and run your Java code
online
class Main {
public static void main(String[] args) {
int max, n;
Scanner sc = new Scanner(System.in);
System.out.println("enter array length");
n = sc.nextInt();
max = 0;
int a[] = new int[n];
for (int i=0;i<=n-1;i++)
{
a[i]=i;
System.out.println(a[i]*10);
}
}
}