AmitDiwan has Published 10744 Articles

Java Program for Smallest K digit number divisible by X

AmitDiwan

AmitDiwan

Updated on 08-Jul-2020 11:23:11

213 Views

To find the smallest K digit number divisible by X, the Java code is as follows −Example Live Demoimport java.io.*; import java.lang.*; public class Demo{    public static double smallest_k(double x_val, double k_val){       double val = 10;       double MIN = Math.pow(val, k_val - 1);   ... Read More

Java Program for n-th Fibonacci number

AmitDiwan

AmitDiwan

Updated on 08-Jul-2020 10:38:54

5K+ Views

There are multiple ways in which the ‘n’thFibonacci number can be found. Here, we will use dynamic programming technique as well as optimizing the space.Let us see an example −Example Live Demopublic class Demo{    static int fibo(int num){       int first = 0, second = 1, temp;   ... Read More

Replacing ‘public’ with ‘private’ in “main” in Java

AmitDiwan

AmitDiwan

Updated on 08-Jul-2020 10:33:09

396 Views

When ‘public’ is used in ‘main’ −Example Live Demopublic class Demo{    public static void main(String args[]){       System.out.println("This is a sample only");    } }OutputThis is a sample onlyA class named Demo contains the main function that is public. It has a print function, which successfully compiles, executes ... Read More

Replace null values with default value in Java Map

AmitDiwan

AmitDiwan

Updated on 08-Jul-2020 10:29:55

1K+ Views

To replace null values with default value in Java Map, the code is as follows −Example Live Demoimport java.util.*; import java.util.stream.*; public class Demo{    public static Map null_vals(Map my_map, T def_val){       my_map = my_map.entrySet().stream().map(entry -> {          if (entry.getValue() == null)     ... Read More

Static and non static blank final variables in Java

AmitDiwan

AmitDiwan

Updated on 08-Jul-2020 10:28:41

1K+ Views

Static variable: Declared with the help of the keyword ‘static’, they are also known as class variables. They are defined within a constructor or outside a class function. When a variable is static, it is shared between all objects of the class, irrespective of the number of objects that are ... Read More

Java program to find IP Address of the client

AmitDiwan

AmitDiwan

Updated on 08-Jul-2020 10:25:22

2K+ Views

To find the IP Address of the client, the Java code is as follows −Example Live Demoimport java.net.*; import java.io.*; import java.util.*; import java.net.InetAddress; public class Demo{    public static void main(String args[]) throws Exception{       InetAddress my_localhost = InetAddress.getLocalHost();       System.out.println("The IP Address of client is ... Read More

Find the second most repeated word in a sequence in Java

AmitDiwan

AmitDiwan

Updated on 08-Jul-2020 10:20:18

673 Views

To find the second most repeated word in a sequence in Java, the code is as follows −Example Live Demoimport java.util.*; public class Demo{    static String second_repeated(Vector my_seq){       HashMap my_map = new HashMap(my_seq.size()){          @Override          public Integer get(Object key){ ... Read More

Find the first repeated word in a string in Java

AmitDiwan

AmitDiwan

Updated on 08-Jul-2020 10:17:39

950 Views

To find the first repeated word in a string in Java, the code is as follows −Example Live Demoimport java.util.*; public class Demo{    static char repeat_first(char my_str[]){       HashSet my_hash = new HashSet();       for (int i=0; i

Find the uncommon values concatenated from both the strings in Java

AmitDiwan

AmitDiwan

Updated on 08-Jul-2020 10:16:20

272 Views

To find the uncommon values concatenated from both the strings in Java, the code is as follows −Example Live Demoimport java.util.*; import java.lang.*; import java.io.*; public class Demo{    public static String concat_str(String str_1, String str_2){       String result = "";       int i;       ... Read More

How to find all tables that contains columnA and columnB in MySQL?

AmitDiwan

AmitDiwan

Updated on 08-Jul-2020 09:16:49

148 Views

To find specific column names, use information_schema.columns Here, I am using Id in place of columnA and Name in place of columnB −mysql> select table_name as TableNameFromWebDatabase    -> from information_schema.columns    -> where column_name IN ('Id', 'Name')    -> group by table_name    -> having count(*) = 3;This will ... Read More

Advertisements