Java Articles

Page 120 of 450

Write a Java program to capitalize each word in the string?

Akshaya Akki
Akshaya Akki
Updated on 11-Mar-2026 2K+ Views

You can capitalize words in a string using the toUpperCase() method of the String class. This method converts the contents of the current string to Upper case letters.Examplepublic class StringToUpperCaseEmp {    public static void main(String[] args) {       String str = "string abc touppercase ";       String strUpper = str.toUpperCase();       System.out.println("Original String: " + str);       System.out.println("String changed to upper case: " + strUpper);    } }OutputOriginal String: string abc touppercase String changed to upper case: STRING ABC TOUPPERCASE

Read More

Java Program to check whether one String is a rotation of another.

Ayyan
Ayyan
Updated on 11-Mar-2026 635 Views

To find weather a string is rotation of another, concat the first string to itself twice and find weatherExamplepublic class Sample {    public static void main(String args[]){       String str1 = "gala";       String str2 = "alag";       String s3 = str1+str1;       if(s3.contains(str2)) {          System.out.println("str1 is rotation of str2");       } else {          System.out.println("str1 is not rotation of str2");       }    } }

Read More

Write a java program reverse tOGGLE each word in the string?

Manikanth Mani
Manikanth Mani
Updated on 11-Mar-2026 909 Views

To perform a reverse toggle split the words of a string, reverse each word using the split() method, change the first letter of each word to lower case and remaining letters to upper case.Exampleimport java.lang.StringBuffer; public class ToggleReverse {    public static void main(String args[]){       String sample = "Hello How are you";       String[] words = sample.split(" ");       String result = "";       for(String word:words){          StringBuffer s = new StringBuffer(word);          word = s.reverse().toString();          String firstSub = word.substring(0, 1);          String secondSub = word.substring(1);          result = result+firstSub.toLowerCase()+secondSub.toUpperCase()+" ";       }       System.out.println(result);    } }OutputoLLEH wOH eRA uOY

Read More

How to swap two String variables without third variable.

Akshaya Akki
Akshaya Akki
Updated on 11-Mar-2026 3K+ Views

To swap the contents of two strings (say s1 and s2) without the third, first of all concatenate them and store in s1. Now using the substring() method of the String class store the value of s1 in s2 and vice versa.Examplepublic class Sample {    public static void main(String args[]){       String s1 = "tutorials";       String s2 = "point";       System.out.println("Value of s1 before swapping :"+s1);       System.out.println("Value of s2 before swapping :"+s2);       int i = s1.length();       s1 = s1+s2;       s2 = s1.substring(0, ...

Read More

Modular Exponentiation (Power in Modular Arithmetic) in java

George John
George John
Updated on 11-Mar-2026 1K+ Views

The java.math.BigInteger.modPow(BigInteger exponent, BigInteger m) returns a BigInteger whose value is (thisexponent mod m). Unlike pow, this method permits negative exponents. You can calculate the modular Exponentiation using this method.Programimport java.math.*; public class BigIntegerDemo {    public static void main(String[] args) {       // create 3 BigInteger objects       BigInteger bi1, bi2, bi3;             // create a BigInteger exponent       BigInteger exponent = new BigInteger("2");       bi1 = new BigInteger("7");       bi2 = new BigInteger("20");             // perform modPow operation on bi1 using bi2 and exp       bi3 = bi1.modPow(exponent, bi2);       String str = bi1 + "^" +exponent+ " mod " + bi2 + " is " +bi3;             // print bi3 value       System.out.println( str );    } }Output:7^2 mod 20 is 9

Read More

Modular Exponentiation (Power in Modular Arithmetic) in java

George John
George John
Updated on 11-Mar-2026 1K+ Views

The java.math.BigInteger.modPow(BigInteger exponent, BigInteger m) returns a BigInteger whose value is (thisexponent mod m). Unlike pow, this method permits negative exponents. You can calculate the modular Exponentiation using this method.Programimport java.math.*; public class BigIntegerDemo {    public static void main(String[] args) {       // create 3 BigInteger objects       BigInteger bi1, bi2, bi3;             // create a BigInteger exponent       BigInteger exponent = new BigInteger("2");       bi1 = new BigInteger("7");       bi2 = new BigInteger("20");             // perform modPow operation on bi1 using bi2 and exp       bi3 = bi1.modPow(exponent, bi2);       String str = bi1 + "^" +exponent+ " mod " + bi2 + " is " +bi3;             // print bi3 value       System.out.println( str );    } }Output:7^2 mod 20 is 9

Read More

Modular multiplicative inverse in java

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 1K+ Views

The java.math.BigInteger.modInverse(BigInteger m) returns a BigInteger whose value is (this-1 mod m). Using this method you can calculate Modular multiplicative inverse for a given number.Programimport java.math.*; public class BigIntegerDemo {    public static void main(String[] args) {       // create 3 BigInteger objects       BigInteger bi1, bi2, bi3;             // create a BigInteger exponent       BigInteger exponent = new BigInteger("2");       bi1 = new BigInteger("7");       bi2 = new BigInteger("20");             // perform modPow operation on bi1 using bi2 and exp       bi3 = bi1.modPow(exponent, bi2);       String str = bi1 + "^" +exponent+ " mod " + bi2 + " is " +bi3;             // print bi3 value       System.out.println( str );    } }Output7^2 mod 20 is 9

Read More

Modular multiplicative inverse in java

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 1K+ Views

The java.math.BigInteger.modInverse(BigInteger m) returns a BigInteger whose value is (this-1 mod m). Using this method you can calculate Modular multiplicative inverse for a given number.Programimport java.math.*; public class BigIntegerDemo {    public static void main(String[] args) {       // create 3 BigInteger objects       BigInteger bi1, bi2, bi3;             // create a BigInteger exponent       BigInteger exponent = new BigInteger("2");       bi1 = new BigInteger("7");       bi2 = new BigInteger("20");             // perform modPow operation on bi1 using bi2 and exp       bi3 = bi1.modPow(exponent, bi2);       String str = bi1 + "^" +exponent+ " mod " + bi2 + " is " +bi3;             // print bi3 value       System.out.println( str );    } }Output7^2 mod 20 is 9

Read More

Pollard's Rho Algorithm for Prime Factorization in java

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 364 Views

It is an algorithm to perform factorization on given integers. Following is the program implementing the Rho Algorithm for Prime Factorization.Programpublic class PollardsRho {    int num = 65;    public int gcd(int a, int b) {       int gcd = 0;       for(int i = 1; i

Read More

Pollard's Rho Algorithm for Prime Factorization in java

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 364 Views

It is an algorithm to perform factorization on given integers. Following is the program implementing the Rho Algorithm for Prime Factorization.Programpublic class PollardsRho {    int num = 65;    public int gcd(int a, int b) {       int gcd = 0;       for(int i = 1; i

Read More
Showing 1191–1200 of 4,498 articles
« Prev 1 118 119 120 121 122 450 Next »
Advertisements