Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Java Articles
Page 19 of 450
Search a string in Matrix Using Split function in Java
To search a string in Matrix using split function, the code is as follows −Exampleimport java.util.*; public class Demo { public static int search_string(String[] my_matrix, String search_string){ for (String input : my_matrix){ String[] my_value = input.split(search_string); if (my_value.length >= 2 || my_value.length == 0){ return 1; } else if (my_value.length == 1 && input.length() != my_value[0].length()){ return 1; } } ...
Read MoreJava Program to Find sum of Series with n-th term as n^2 – (n-1)^2
To find the sum of such series, the Java program is as follows −Examplepublic class Demo { static long my_val = 1000000007; public static long compute_val(long my_int){ return ((my_int % my_val) * (my_int % my_val)) % my_val; } public static void main(String[] args){ long my_int = 45687234; System.out.println("The computed value is "); System.out.print(compute_val(my_int)); } }OutputThe computed value is 335959495A class named Demo defines a function named ‘compute_val’ that computes and returns the sum of a specific series. In the main function, the long ...
Read MoreJava Program for Stooge Sort
Following is the Java program for Stooge sort −Exampleimport java.io.*; public class Demo { static void stooge_sort(int my_arr[], int l_val, int h_val){ if (l_val >= h_val) return; if (my_arr[l_val] > my_arr[h_val]){ int temp = my_arr[l_val]; my_arr[l_val] = my_arr[h_val]; my_arr[h_val] = temp; } if (h_val-l_val+1 > 2){ int temp = (h_val-l_val+1) / 3; stooge_sort(my_arr, l_val, h_val-temp); stooge_sort(my_arr, l_val+temp, h_val); ...
Read MoreJava Program for Standard Normal Distribution (SND)
Following is the Java program for Standard Normal Distribution −Exampleimport java.io.*; import java.util.*; public class Demo{ public static void main(String[] args){ double std_dev, val_1, val_3, val_2; val_1 = 68; val_2 = 102; val_3 = 26; std_dev = (val_1 - val_2) / val_3; System.out.println("The standard normal deviation is: " + std_dev); } }OutputThe standard normal deviation is: -1.3076923076923077A class named Demo contains the main function, where certain double values are defined, and the formula for standard deviation is applied ((val_1 - val_2) / val_3) on these values and the resultant output is displayed on the console.
Read MoreStatic Control Flow in Java
The Static Control Flow identify static members, executes static blocks, and then executes the static main method. Let us see an example −Examplepublic class Demo{ static int a = 97; public static void main(String[] args){ print(); System.out.println("The main method has completed executing"); } static{ System.out.println(a); print(); System.out.println("We are inside the first static block"); } public static void print(){ System.out.println(b); } static{ System.out.println("We are inside the second static block"); } ...
Read MoreStatic method in Interface in Java
To implement static method in Interface, the Java code is as follows −Exampleinterface my_interface{ static void static_fun(){ System.out.println("In the newly created static method"); } void method_override(String str); } public class Demo_interface implements my_interface{ public static void main(String[] args){ Demo_interface demo_inter = new Demo_interface(); my_interface.static_fun(); demo_inter.method_override("In the override method"); } @Override public void method_override(String str){ System.out.println(str); } }OutputIn the newly created static method In the override methodAn interface is defined, inside which a static function is defined. Another ...
Read MoreCan we call run() method directly instead of start() in Java
Yes, we can do that. Let us see an example −Exampleclass my_thread extends Thread{ public void run(){ try{ System.out.println ("The thread " + Thread.currentThread().getId() + " is currently running"); } catch (Exception e){ System.out.println ("The exception has been caught"); } } } public class Main{ public static void main(String[] args){ int n = 6; for (int i=1; i
Read MoreThread Interference Error in Java
Let us see an example to understand the concept of Thread Interference error −Exampleimport java.io.*; class Demo_instance{ static int val_1 = 6; void increment_val(){ for(int j=1;j
Read MoreWidening Primitive Conversion in Java
Following is an example showing widening primitive conversion −Examplepublic class Demo { public static void main(String[] args) { System.out.print("H" + "E"); System.out.print('L'); System.out.print('L'); System.out.print('O'); } }OutputHELLOA class named Demo contains the main function. Here, the ‘print’ function is used to print specific characters in double quotes and then in single quotes. When the process of widening primitive conversion happens, the presence of ‘+’ operator is a must. This ‘+’ operator expects integer on both the left hand and right hand sides.
Read MoreJava program to convert floating to binary
To convert floating to binary, the Java code is as follows −Exampleimport java.io.*; public class Demo { static void decimal_to_bin(int n){ int[] bin_num = new int[50]; int i = 0; while (n > 0){ bin_num[i] = n % 2; n = n / 2; i++; } for (int j = i - 1; j >= 0; j--) System.out.print(bin_num[j]); } public static void main (String[] args){ ...
Read More