![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9326 Articles for Object Oriented Programming
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
3K+ Views
You can calculate the GCD of given two numbers, using recursion as shown in the following program.Exampleimport java.util.Scanner; public class GCDUsingRecursion { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter first number :: "); int firstNum = sc.nextInt(); System.out.println("Enter second number :: "); int secondNum = sc.nextInt(); System.out.println("GCD of given two numbers is ::"+gcd(firstNum, secondNum)); } public static int gcd(int num1, int num2) { if (num2 != 0){ return gcd(num2, num1 % num2); } else{ return num1; } } }OutputEnter first number :: 625 Enter second number :: 125 GCD of given two numbers is ::125
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
872 Views
ExampleFollowing is a program to multiply given floating point numbers.import java.util.Scanner; public class MultiplyFloatingNumbers { public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.println("Enter first floating point number."); float flt1 = sc.nextFloat(); System.out.println("Enter second floating point number."); float flt2 = sc.nextFloat(); float product = flt1*flt2; System.out.println("Product of given floating point numbers ::"+product); } }OutputEnter first floating point number. 2.2 Enter second floating point number. 6.3 Product of given floating point numbers ::13.860001
![Lakshmi Srinivas](https://www.tutorialspoint.com/assets/profiles/13528/profile/60_91717-1512651120.jpg)
13K+ Views
The Set object provides a method known as toArray(). This method accepts an empty array as argument, converts the current Set to an array and places in the given array. To convert a Set object to an array − Create a Set object. Add elements to it. Create an empty array with size of the created Set. Convert the Set to an array using the toArray() method, bypassing the above-created array as an argument to it. Print the contents of the array.ExampleLive Demoimport java.util.HashSet; import java.util.Set; public class SetToArray { public static void main(String args[]){ Set set = new HashSet(); ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
26K+ Views
The Map class's object contains key and value pairs. You can convert it into two list objects one which contains key values and the one which contains map values separately. To convert a map to list − Create a Map object. Using the put() method insert elements to it as key, value pairs Create an ArrayList of integer type to hold the keys of the map. In its constructor call the method keySet() of the Map class. Create an ArrayList of String type to hold the values of the map. In ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
3K+ Views
The addAll() method of the java.util.ArrayList class is used to insert all of the elements in the specified collection into this list. To add contents of a list to another −Create list1 by instantiating list objects (in this example we used ArrayList).Add elements to it using add() method.Create another list. Add elements to it.Now add the elements of one list to other using the addAll() method.ExampleLive Demoimport java.util.ArrayList; public class JoinTwoLists { public static void main(String args[]){ ArrayList list1 = new ArrayList(); list1.add("Apple"); list1.add("Orange"); list1.add("Banana"); ... Read More
![Lakshmi Srinivas](https://www.tutorialspoint.com/assets/profiles/13528/profile/60_91717-1512651120.jpg)
17K+ Views
The List object provides a method known as toArray(). This method accepts an empty array as argument, converts the current list to an array and places in the given array. To convert a List object to an array − Create a List object. Add elements to it. Create an empty array with size of the created ArrayList. Convert the list to an array using the toArray() method, bypassing the above-created array as an argument to it. Print the contents of the array.ExampleLive Demoimport java.util.ArrayList; public class ListToArray { public static void main(String args[]){ ArrayList list = new ArrayList(); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
6K+ Views
The Java.io.BufferedWriter class writes text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings. To add contents to a file − Instantiate the BufferedWriter class. By passing the FileWriter object as an argument to its constructor. Write data to the file using the write() method.Exampleimport java.io.File; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.IOException; public class AppendToFileExample { public static void main( String[] args ) { try { String data = " Tutorials Point is a best website in the world"; ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
72 Views
Following is an example to add a given time to a particular date.ProgramLive Demoimport java.util.*; public class Main { public static void main(String[] args) throws Exception { Date d1 = new Date(); Calendar cl = Calendar. getInstance(); cl.setTime(d1); System.out.println("today is " + d1.toString()); cl. add(Calendar.MONTH, 1); System.out.println("date after a month will be " + cl.getTime().toString() ); cl. add(Calendar.HOUR, 70); System.out.println("date after 7 hrs will be " + cl.getTime().toString() ); cl. add(Calendar.YEAR, ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
514 Views
The toString() method of the Character class converts the character to string. You can use this method to convert the given character to String.Exampleimport java.util.Scanner; public class CharToString { public static void main(String args[]){ System.out.println("Enter a character ::"); Scanner sc = new Scanner(System.in); char ch = sc.next().charAt(0); String str = Character.toString(ch); System.out.println(str); } }OutputEnter a character :: h h
![Lakshmi Srinivas](https://www.tutorialspoint.com/assets/profiles/13528/profile/60_91717-1512651120.jpg)
28K+ Views
Percent means percent (hundreds), i.e., a ratio of the parts out of 100. The symbol of a percent is %. We generally count the percentage of marks obtained, return on investment etc. The percentage can go beyond 100% also.For Example, assuming that we have total and a part. So we say what part is what percent of total and should be calculated as −percentage = ( part / total ) × 100AlgorithmBelow is the algorithm to calculate percentage in Java:1. Collect values for part and total 2. Apply formula { percentage = ( part / total ) × 100 } ... Read More