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

Java Method Practice Questions for Beginners

The document provides a series of Java method practice questions for beginners, covering basic methods, loops with methods, method overloading, and return types with parameters. It includes tasks such as writing methods for arithmetic operations, checking number properties, and manipulating strings. Additionally, it features a sample Java code snippet that demonstrates storing multiples of 10 in an array and printing them.

Uploaded by

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

Java Method Practice Questions for Beginners

The document provides a series of Java method practice questions for beginners, covering basic methods, loops with methods, method overloading, and return types with parameters. It includes tasks such as writing methods for arithmetic operations, checking number properties, and manipulating strings. Additionally, it features a sample Java code snippet that demonstrates storing multiples of 10 in an array and printing them.

Uploaded by

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

Java Method Practice Questions for

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.

With Loops + Methods


 Write a method to print the multiplication table of a given number.
 Create a method that takes a number and prints all even numbers up to it.
 Write a method to count the number of digits in a number.
 Create a method that reverses a given number.
 Write a method to find the sum of digits of a number.

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.

Return Types & Parameters


 Write a method that accepts a name and returns a welcome message.
 Create a method that takes a string and returns it in reverse.
 Write a method that converts Celsius to Fahrenheit.
 Create a method that checks if a string is a palindrome.


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);
 }

 }
}

You might also like