- Trending Categories
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 2617 Articles for Java
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
434 Views
Following is the Java program for GCD of more than two numbers −Example Live Demopublic class Demo{ static int gcd_of_nums(int val_1, int val_2){ if (val_1 == 0) return val_2; return gcd_of_nums(val_2 % val_1, val_1); } static int find_gcd(int arr[], int no){ int result = arr[0]; for (int i = 1; i < no; i++){ result = gcd_of_nums(arr[i], result); if(result == 1){ return 1; } ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
212 Views
Following is the Java code for focal length of a spherical mirror −Example Live Demoimport java.util.*; import java.lang.*; public class Demo{ public static float concave_f_len(float val){ return val/2 ; } public static float convex_f_len(float val){ return - (val/2 ) ; } public static void main(String argc[]){ float val = 55 ; System.out.print("The focal length of spherical mirror (concave) is : " + concave_f_len(val) + "units"); System.out.println("The focal length of spherical mirror (convex) is : "+ convex_f_len(val) + "units"); } }OutputThe ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
128 Views
Following is the Java program to find the vertex, focus and directrix of a parabola −Example Live Demopublic class Demo{ public static void find_values(float val_1, float val_2, float val_3){ System.out.println("The value of vertex is (" + (-val_2 / (2 * val_1)) + ", "+ (((4 * val_1 * val_3) - (val_2 * val_2)) / (4 * val_1)) + ")"); System.out.println("The value of focus is (" + (-val_2 / (2 * val_1)) + ", " + (((4 * val_1 * val_3) - (val_2 * val_2) + 1) / (4 * val_1)) + ")"); ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
182 Views
Following is the Java code to find the perimeter of a cylinder −Example Live Demoimport java.io.*; public class Demo{ static int find_peri(int dia, int ht){ return 2*(dia + ht); } public static void main(String[] args){ int dia = 7; int ht = 15; System.out.println("The perimeter of the cylinder is " + find_peri(dia, ht) + " units"); } }OutputThe perimeter of the cylinder is 44 unitsA class named Demo defines a static function that takes in two values, diameter and height. This function computes the sum ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
Following is the Java code to find the largest prime factor of a number −Example Live Demoimport java.io.*; import java.util.*; public class Demo{ static long maxPrimeFactors( long val){ long max_prime = -1; while (val % 2 == 0) { max_prime = 2; val >>= 1; } for (int i = 3; i 2) max_prime = val; return max_prime; } public static void main(String[] args){ int val = 148592; ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
121 Views
Followimg is the code to implement String formatting in Java using % −Example Live Demopublic class Demo { public static void main(String args[]){ String my_str = " sample."; String concat_Str = String.format("This is a" + "%s", my_str); String format_str_1 = String.format("The value is %.4f", 78.92367); System.out.println(concat_Str); System.out.println(format_str_1); } }OutputThis is a sample. The value is 78.9237A class named Demo contains the main function. Here a string value is defined, which is used to format the string, by concatenating it to another variable. Similarly, a ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
508 Views
Following is an example for Common Divisors of Two numbers in Java −Example Live Demopublic class Demo{ static int find_gcd(int val_1, int val_2){ if (val_1 == 0) return val_2; return find_gcd(val_2%val_1,val_1); } static int common_divisors(int val_1,int val_2){ int no = find_gcd(val_1, val_2); int result = 0; for (int i=1; i
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
142 Views
In Bitonic Sort, the comparision is in predefined sequence (Bitonic sequence), not dependent on the data to be sorted. Let us see an example for Bitonic Sort Java program −Example Live Demopublic class Demo{ void compare_swap(int my_arr[], int i, int j, int direction){ if ((my_arr[i] > my_arr[j] && direction == 1) || (my_arr[i] < my_arr[j] && direction == 0)){ int temp = my_arr[i]; my_arr[i] = my_arr[j]; my_arr[j] = temp; } } void merge_vals(int my_arr[], int low, int cnt, int direction){ ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
5K+ Views
Following is the program for Recursive Binary Search in Java −Example Live Demopublic class Demo{ int rec_bin_search(int my_arr[], int left, int right, int x){ if (right >= left){ int mid = left + (right - left) / 2; if (my_arr[mid] == x) return mid; if (my_arr[mid] > x) return rec_bin_search(my_arr, left, mid - 1, x); return rec_bin_search(my_arr, mid + 1, right, x); } return -1; } ... Read More