Articles on Trending Technologies

Technical articles with clear explanations and examples

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

How to convert a Java String to an Int?

Alankritha Ammu
Alankritha Ammu
Updated on 11-Mar-2026 428 Views

The parseXxx() method is used to get the primitive data type of a certain String. In this case to convert a String to integer you could use the parseInt() method.Examplepublic class Test {    public static void main(String args[]) {       int x =Integer.parseInt("9");       double c = Double.parseDouble("5");       int b = Integer.parseInt("444",16);       System.out.println(x);       System.out.println(c);       System.out.println(b);    } }Output9 5.0 1092

Read More

What is the difference between super and this, keywords in Java?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 11-Mar-2026 770 Views

The this is a keyword in Java which is used as a reference to the object of the current class. Using it you can − Differentiate the instance variables from local variables if they have same names, within a constructor or a method. Call one type of constructor (parametrized constructor or default) from other in a class. It is known as explicit constructor invocation. Example class Superclass { int age; Superclass(int age) { this.age = age; } public void ...

Read More

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 645 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

Pollard's Rho Algorithm for Prime Factorization in java

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 365 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

Where do we use $.extend() method in jQuery?

David Meador
David Meador
Updated on 11-Mar-2026 1K+ Views

The jQuery.extend() method is used to merge contents of two or more objects together. The object is merged into the first object. You can try to run the following code to learn how to use extend() method −Example $(document).ready(function() {   $("#button1").click(function() {     var obj1 = {       maths: 60,       history: {pages: 150,price: 400,lessons: 30},       science: 120     };     var obj2 = {       history: { price: 150, lessons: 24 },       economics: 250     };     $.extend(true, obj1, obj2);     $("#demo").append(JSON.stringify(obj1));    }); });    Result    

Read More

How to determine the OS the computer is running using Java?

Sreemaha
Sreemaha
Updated on 11-Mar-2026 257 Views

The System class of java.lang package provides a method named getProperty() this method accepts one of the following string parameters an returns the respective property. java.class.path − If you pass this value as a parameter, the getProperty() method returns the current classpath. java.home − If you pass this value as a parameter, the getProperty() method returns the current Installation directory of the JRE. java.vendor − If you pass this value as a parameter, the getProperty() method returns the current vendor name of the JRE. java.vendor.url − If you pass this value as a parameter, the getProperty() method returns the ...

Read More

How to execute a static block without main method in Java?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 2K+ Views

VM first looks for the main method (at least the latest versions) and then, starts executing the program including static block. Therefore, you cannot execute a static block without main method. Example public class Sample { static { System.out.println("Hello how are you"); } } Since the above program doesn’t have a main method, If you compile and execute it you will get an error message. C:\Sample>javac StaticBlockExample.java C:\Sample>java StaticBlockExample Error: Main method not found in class StaticBlockExample, please define the main method as: public static ...

Read More

Fibonacci series program in Java without using recursion.

Syed Javed
Syed Javed
Updated on 11-Mar-2026 4K+ Views

Following is the required program.Examplepublic class Tester {    public static void main(String args[]) {        int n1 = 0, n2 = 1, n3, i, max = 5;        System.out.print(n1 + " " + n2);        for (i = 2; i < max; ++i) {           n3 = n1 + n2;           System.out.print(" " + n3);           n1 = n2;           n2 = n3;        }     }  }Output0 1 1 2 3

Read More
Showing 30181–30190 of 61,297 articles
Advertisements