AmitDiwan has Published 10744 Articles

Java Program for Stooge Sort

AmitDiwan

AmitDiwan

Updated on 13-Jul-2020 12:18:16

186 Views

Following is the Java program for Stooge sort −Example Live Demoimport 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]; ... Read More

Java Program to Find sum of Series with n-th term as n^2 – (n-1)^2

AmitDiwan

AmitDiwan

Updated on 13-Jul-2020 12:13:45

273 Views

To find the sum of such series, the Java program is as follows −Example Live Demopublic 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[] ... Read More

Search a string in Matrix Using Split function in Java

AmitDiwan

AmitDiwan

Updated on 13-Jul-2020 12:08:20

127 Views

To search a string in Matrix using split function, the code is as follows −Example Live Demoimport 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 ... Read More

Perl vs Java

AmitDiwan

AmitDiwan

Updated on 13-Jul-2020 12:04:56

363 Views

JavaJava is an object oriented programming language as well as a computing platform.It is safe, quick and reliable.The code in Java is first converted into bytecode and then executed using a JVM (Java Virtual Machine).The java program that is converted into bytecode is stored with the help of the extension ... Read More

Package Imports in JShell of Java 9

AmitDiwan

AmitDiwan

Updated on 13-Jul-2020 12:03:22

306 Views

In general, 10 packages are imported using the JShell.The following command shows the packages that were imported by default.jshell> /importOutputimport java.io.* import java.math.* import java.net.* import java.nio.file* import java.sql.* import java.util.* import java.util.regex* import java.util.function* import java.util.prefs* import java.util.stream.*Importing a specific package using JShelljshell> import java.util.*;Read More

Method Overloading and Ambiguity in Varargs in Java

AmitDiwan

AmitDiwan

Updated on 13-Jul-2020 12:02:11

1K+ Views

There are ambiguities while using variable arguments in Java. This happens because two methods can definitely be valid enough to be called by data values. Due to this, the compiler doesn’t have the knowledge as to which method to call.Example Live Demopublic class Demo {    static void my_fun(double ... my_Val){ ... Read More

How to input multiple values from user in one line in Java?

AmitDiwan

AmitDiwan

Updated on 13-Jul-2020 12:00:31

13K+ Views

To input multiple values from user in one line, the code is as follows −Example Live Demoimport java.util.Scanner; public class Demo {    public static void main(String[] args) {       System.out.print("Enter two floating point values : ");       Scanner my_scan = new Scanner(System.in);       double ... Read More

How a thread can interrupt another thread in Java?

AmitDiwan

AmitDiwan

Updated on 13-Jul-2020 11:57:50

958 Views

The ‘interrupt’ function can be used in Java to interrupt the execution of a thread with the help of the exception InterruptedException.The below example shows how the currently executing thread stops execution (because of a new exception raised in the catch block) once it is interrupted −Example Live Demopublic class Demo ... Read More

Why Kotlin will replace Java for Android App Development

AmitDiwan

AmitDiwan

Updated on 13-Jul-2020 11:54:59

254 Views

While working with Kotlin, Java libraries and frameworks can be used. This can be done with the help of advanced frameworks, without having to change the whole project. Java and Kotlin co-exist and can be present in the same project.Kotlin code can be placed inside Android Studio, without making the ... Read More

Sum of list with stream filter in Java

AmitDiwan

AmitDiwan

Updated on 13-Jul-2020 11:53:38

1K+ Views

To get sum of list with stream filter in Java, the code is as follows −Example Live Demoimport java.util.*; public class Demo {    public static void main(String[] args)    {       List my_list = new ArrayList();       my_list.add(11);       my_list.add(35);       my_list.add(56); ... Read More

Advertisements