Programming Articles

Page 1487 of 2547

How to move files using FileUtils in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 920 Views

Using the File classThe class named File of the java.io package represents a file or directory (pathnames) in the system. This class provides various methods to perform various operations on files/directories.This class provides various methods to manipulate files, The rename() method of the File class accepts a String representing a destination file and, renames the abstract file path of the current file to the given one.This method actually moves the file from the source path to the destination path.Exampleimport java.io.File; public class MovingFile {    public static void main(String args[]) {       //Creating a source file object   ...

Read More

Bisymmetric matrix in C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 257 Views

Here we will see one program that will help to check whether a matrix is bisymmetric or not. The Bisymmetric matrix is one square matrix that are symmetric about both of the major diagonals. The below matrix is an example of bisymmetric matrix.1 2 3 4 5 2 6 7 8 4 3 7 9 7 3 4 8 7 6 2 5 4 3 2 1AlgorithmcheckBiSymmetric(mat, n)Begin    for i in range 0 to n – 1, do       for j in range 0 to i – 1, do          if mat[i, j] is ...

Read More

Check if a number is in given base or not in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 339 Views

Suppose, we have a number string, we have to find that the number is of given base B or not? If the string is “101110”, b = 2, then the program will return true. If the string is “A8F”, base is 16, it will be true.The approach is very simple. If all of the character is in the range of symbols of the given base, then return true, otherwise false.Example#include using namespace std; bool inGivenBase(string s, int base) {    if (base > 16) //program can handle upto base 1       return false;       else ...

Read More

Check if a number is jumbled or not in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 566 Views

Here we will see one interesting problem to check whether a number is jumbled or not. A number is said to be jumbled if, for every digit, it's neighbor digit differs by max 1. For example, a number 1223 is jumbled, but 1256 is not jumbled.To solve this problem, we have to check if a digit has a neighbor with a difference greater than 1. If such digit is found, then return false, otherwise true.Example#include #include using namespace std; bool isJumbled(int number) {    if (number / 10 == 0) //for single digit number is is always jumbled ...

Read More

Check if a number is perfect square without finding square root in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose a number is given, we have to check whether the number is a perfect square or not. We will not use the square root operation to check it. Suppose a number 1024 is there, this is a perfect square, but 1000 is not a perfect square. The logic is simple, we have to follow this algorithm to get the result.AlgorithmisPerfectSquare(n) −input − The number noutput − true, if the number is a perfect square, otherwise, falsebegin    for i := 1, i2 ≤ n, increase i by 1:       if n is divisible by i, and n ...

Read More

What are variable arguments in java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 770 Views

While defining a method, In general, we will specify the arguments it accepts along with the type as −myMethod(int a, String b){ }Suppose if you need to accept more than one variable of the same type you need to specify the variables one after the other as −myMethod(int a, int b, int c){ }You can also pass a variable number of arguments of a particular type, to a method. These are known as variable arguments or, varargs. They are represented by three dots (…)Syntaxpublic myMethod(int ... a) {    // method body }Once you use variable arguments as a parameter ...

Read More

BufferedReader class in Java.

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 8K+ Views

The BufferedReader class of Java is used to read the stream of characters from the specified source (character-input stream). The constructor of this class accepts an InputStream object as a parameter.This class provides a method named read() and readLine() which reads and returns the character and next line from the source (respectively) and returns them.Instantiate an InputStreamReader class bypassing your InputStream object as a parameter.Then, create a BufferedReader, bypassing the above obtained InputStreamReader object as a parameter.Now, read data from the current reader as String using the readLine() or read() method.ExampleThe following Java program demonstrates how to read integer data ...

Read More

Check if a number is power of 8 or not in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 559 Views

In this section, we will see, if a number is the power of 8 or not using some easier method. If a number like 4096 is there, then the program will return true, as this is the power of 8.The trick is simple. we will calculate log8(num). If this is an integer, then n is the power of 8. Here we will use the tranc(n) function to find the closest integer of the double value.Example#include #include using namespace std; bool isPowerOfEight(int n) {    double val = log(n)/log(8); //get log n to the base 8    return (val ...

Read More

Check if a number is power of k using base changing methods in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 282 Views

Here we will see a program, if one number is given, another value k is also given, we have to check whether the number is power of k or not. But we have to perform the base changing method to solve this problem. Suppose a number is 27, and k = 3. Then by base changing method, the 27 will be 10003. Here after changing the base if there is only one occurrence of digit 1, and others are 0, then the number is power of k.To solve this problem, we will follow these steps.Steps −define flag := falsewhile number > ...

Read More

Program for Celsius To Fahrenheit conversion in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 911 Views

Given with temperature ‘n’ in Celsius the challenge is to convert the given temperature to Fahrenheit and display it.ExampleInput 1-: 100.00    Output -: 212.00 Input 2-: -40    Output-: -40For converting the temperature from Celsius to Fahrenheit there is a formula which is given belowT(°F) = T(°C) × 9/5 + 32Where, T(°C) is temperature in Celsius and T(°F) is temperature in FahrenheitApproach used below is as followsInput temperature in a float variable let’s say CelsiusApply the formula to convert the temperature into FahrenheitPrint FahrenheitALGORITHMStart Step 1 -> Declare a function to convert Celsius to Fahrenheit    void cal(float cel) ...

Read More
Showing 14861–14870 of 25,466 articles
Advertisements