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 227 of 450
Java Program to replace one specific character with another
Use the replace() method to replace a specific character with another. Let’s say the following is our string and here we are replacing a whitespace with a $ character.String str1 = "Orange is the new Black!";Now, use the replace() method to replace a character with $str1.replace(' ', '$');Example Live Demopublic class Demo { public static void main(String[] args) { String str1 = "Orange is the new Black!"; System.out.println("String: "+str1); String str2 = str1.replace(' ', '$'); System.out.println("Updated string: "+str2); } }OutputString: Orange is the new Black! Updated string: ...
Read MoreAdd seconds to current date using Calendar.add() method in Java
Import the following package for Calendar class in Java.import java.util.Calendar;Firstly, create a Calendar object and display the current date and time.Calendar calendar = Calendar.getInstance(); System.out.println("Current Date and Time = " + calendar.getTime());Now, let us increment the seconds using the calendar.add() method and Calendar.SECOND constant.calendar.add(Calendar.SECOND, 15);Example Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Current Date = " + calendar.getTime()); // Add 15 seconds to current date calendar.add(Calendar.SECOND, 15); System.out.println("Updated Date = " + calendar.getTime()); } ...
Read MoreGet the Component Type of an Array Object in Java
In order to get the component type of an Array Object in Java, we use the getComponentType() method. The getComponentType() method returns the Class denoting the component type of an array. If the class is not an array class this method returns null.Declaration − The java.lang.Class.getComponentType() method is declared as follows -public Class getComponentType()Let us see a program to the get the component type of an Array Object in Java -Example Live Demopublic class Example { public static void main(String[] args) { int[] array = new int[] {1, 2, 3}; // obtain the Class ...
Read MorePollard’s Rho Algorithm for Prime Factorization in java
It is an algorithm to perform factorization on given integers. Following is the program implementing the Rho Algorithm for Prime Factorization.ProgramLive Demopublic class PollardsRho { int num = 65; public int gcd(int a, int b) { int gcd = 0; for(int i = 1; i
Read MorePollard’s Rho Algorithm for Prime Factorization in java
It is an algorithm to perform factorization on given integers. Following is the program implementing the Rho Algorithm for Prime Factorization.ProgramLive Demopublic class PollardsRho { int num = 65; public int gcd(int a, int b) { int gcd = 0; for(int i = 1; i
Read MoreEuler’s Totient function for all numbers smaller than or equal to n in java
Following is a program to get the result of Euler’s Totient function for all numbers smaller than or equal to n when n is given.Programimport java.util.Scanner; public class EulerTotient { public static int gcd(int a,int b){ int i, hcf = 0; for(i = 1; i
Read MoreEuler’s Totient function for all numbers smaller than or equal to n in java
Following is a program to get the result of Euler’s Totient function for all numbers smaller than or equal to n when n is given.Programimport java.util.Scanner; public class EulerTotient { public static int gcd(int a,int b){ int i, hcf = 0; for(i = 1; i
Read MoreEuler’s criterion in java
According to Euler’s criterion a square root of n under modulo p exists if and only if a number num exists such that num%p is equal to n%p.Programimport java.util.Scanner; public class EulersCriterion { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter n value :"); int n = sc.nextInt(); System.out.println("Enter p value :"); int p = sc.nextInt(); n = n % p; int flag = 0; for ...
Read MoreEuler’s criterion in java
According to Euler’s criterion a square root of n under modulo p exists if and only if a number num exists such that num%p is equal to n%p.Programimport java.util.Scanner; public class EulersCriterion { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter n value :"); int n = sc.nextInt(); System.out.println("Enter p value :"); int p = sc.nextInt(); n = n % p; int flag = 0; for ...
Read MoreDivisors of factorials of a number in java
Following is a Java program to find the divisors of factorials of a number.Programimport java.util.Scanner; public class DivisorsOfFactorial { public static long fact(int i) { if(i
Read More