Found 33676 Articles for Programming

Java Program for Standard Normal Distribution (SND)

AmitDiwan
Updated on 13-Jul-2020 12:25:50

375 Views

Following is the Java program for Standard Normal Distribution −Example Live Demoimport 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.

Java program to replace a word with asterisks in a sentence

AmitDiwan
Updated on 24-Jul-2024 21:48:46

3K+ Views

In this article, we will learn how to replace a specific word in a sentence with asterisks using Java. This technique can be useful for obscuring certain words in a text for privacy or censorship purposes. Problem Statement Develop a program in Java that takes a sentence and a word to be censored as input, then outputs the sentence with the specified word replaced by asterisks, while preserving the original format of the sentence. Input This is a sample only, the sky is blue, water is transparent Output This is a ****** only, the sky is blue, water is transparent ... Read More

Java program to check if a string contains any special character

AmitDiwan
Updated on 12-Aug-2024 23:14:29

5K+ Views

In Java, checking if a string contains special characters can be easily done using regular expressions. We will be using the Pattern and Matcher classes from the java.util.regex package, we can efficiently determine whether a string includes any special characters. In this article, we will demonstrate how to use these classes to perform the check and handle the result accordingly. − Problem Statement For a given string write a Java program to check if it contains any special character or not − Input 1 I Love Tutorialspoint Output 1 Special character not found in the string Input 2 ... Read More

Java Program for Stooge Sort

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

187 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];          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 More

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

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

276 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[] 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 ... Read More

Search a string in Matrix Using Split function in Java

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 (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 More

Perl vs Java

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 ‘.class’.Java doesn’t give any specific way in which associative arrays could be stored, instead there are implementations of various hash functions.Java programs that need to be run are stored with the extension ‘.java’.Java is a statically typed language, i.e type checking is performed during compile-time (not run-time).Single line comments in ... Read More

Package Imports in JShell of Java 9

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

307 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.*;

Method Overloading and Ambiguity in Varargs in Java

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){       System.out.print("fun(double ...): " + "Number of args: " + my_Val.length );       for(double x : my_Val)       System.out.print(x + " ");       System.out.println();    }    static void my_fun(boolean ... my_Val){       System.out.print("fun(boolean ...) " + "The number of ... Read More

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

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 double_val = my_scan.nextFloat();       int int_val = my_scan.nextInt();       System.out.println("The floating point value is : " + double_val + " and the integer value is : "       + int_val);    } }Input56.789 99OutputEnter two floating point values : The floating point value is ... Read More

Advertisements