Programming Articles - Page 1874 of 3366

Java Program for array rotation

AmitDiwan
Updated on 10-Aug-2023 12:12:06

616 Views

An array is a linear data structure that is used to store a group of elements with similar datatypes. It stores data in a sequential manner. Once we create an array we can't change its size i.e. it can store a fixed number of elements. The array comes with a vast application and use case. Also, we can perform numerous operations on arrays. This article will help you to understand the basics of arrays and also, we will make java programs to perform right and left rotation operations on arrays. Java Program for Array Rotation First, let's understand the term ... Read More

Java program to print number series without using any loop

AmitDiwan
Updated on 22-Aug-2024 11:58:39

2K+ Views

In this article, we will learn how to print a sequence of numbers in Java, ranging from 0 to 15. To do this, we'll use recursion rather than using loops like for loop or while loop. Recursion is a programming technique where a method calls itself to perform a sub-operation as necessary. Problem Statement Write a Java program to print Number series without using any loop Output The numbers without using a loop have been printed below0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, Java program to print number series without using ... Read More

Java Program for Largest K digit number divisible by X

AmitDiwan
Updated on 07-Jul-2020 07:42:12

209 Views

Following is the Java program for largest K digit number divisible by X −Example Live Demoimport java.io.*; import java.lang.*; public class Demo{    public static int largest_k(int val_1, int val_2){       int i = 10;       int MAX = (int)Math.pow(i, val_2) - 1;       return (MAX - (MAX % val_1));    }    public static void main(String[] args){       int val_1 = 25;       int val_2 = 2;       System.out.println("The largest 2 digit number divisible by 25 is ");       System.out.println((int)largest_k(val_1, val_2));    } }OutputThe largest 2 ... Read More

Java program for longest increasing subsequence

AmitDiwan
Updated on 12-Aug-2024 23:12:31

2K+ Views

In this program, we find the length of the longest increasing subsequence (LIS) in an integer array using Java programming language. An increasing subsequence is a sequence of numbers where each number is greater than the previous one. The program uses a dynamic programming approach to compute the longest increasing subsequence efficiently. This technique involves building a solution using previously computed results. Problem Statement Write a Java program to get the length of the longest increasing subsequence − Input 10, 22, 9, 33, 21, 50, 41, 60 Output The length of the longest increasing subsequence is 5 Steps get ... Read More

How to write text and output it as a text file using R?

Nizamuddin Siddiqui
Updated on 11-Jul-2020 12:56:06

812 Views

The easiest way to write text and obtain it as an output is done by using writeLines function and cat function, and the output of these functions are connected with the help fileConn and sink.Example> fileConn writeLines(c("TutorialsPoint", "SIMPLY EASY LEARNING"), fileConn) > close(fileConn)We can do the same and view these files in R as follows −> fileConn writeLines(c(paste("TutorialsPoint", "E-learning"), "2006", "Video Courses", "Tutorials", "Books"), fileConn) > close(fileConn) > file.show("example.txt")Using sink function> sink("example3.txt") > cat("TutorialsPoint", "E-learning") > cat("") > cat("2006") > cat("") > cat("Video Courses") > cat("") > cat("Tutorials") > cat("") > cat("Books") > sink()Using only cat function> cat("TutorialsPoint E-learning", ... Read More

Which function should be used to load a package in R, require or library?

Nizamuddin Siddiqui
Updated on 06-Jul-2020 15:02:01

536 Views

The main difference between require and library is that require was designed to use inside functions and library is used to load packages. If a package is not available then library throws an error on the other hand require gives a warning message.Using library> library(xyz) Error in library(xyz) : there is no package called ‘xyz’Using requirerequire(xyz) Loading required package: xyz Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘xyz’Here we can see that the library shows an error and require gives a warning message, since warnings are mostly avoided ... Read More

How to deal with “could not find function” error in R?

Nizamuddin Siddiqui
Updated on 06-Jul-2020 15:01:06

10K+ Views

The error “could not find function” occurs due to the following reasons −Function name is incorrect. Always remember that function names are case sensitive in R.The package that contains the function was not installed. We have to install packages in R once before using any function contained by them. It can be done as install.packages("package_name")The package was not loaded before using the function. To use the function that is contained in a package we need to load the package and it can be done as library("package_name").Version of R is older where the function you are using does not exist.If you ... Read More

How to do an inner join and outer join of two data frames in R?

Nizamuddin Siddiqui
Updated on 06-Jul-2020 15:00:12

854 Views

An inner join return only the rows in which the left table have matching keys in the right table and an outer join returns all rows from both tables, join records from the left which have matching keys in the right table. This can be done by using merge function.ExampleInner Join> df1 = data.frame(CustomerId = c(1:5), Product = c(rep("Biscuit", 3), rep("Cream", 2))) > df1   CustomerId Product 1 1 Biscuit 2 2 Biscuit 3 3 Biscuit 4 4 Cream 5 5 Cream > df2 = data.frame(CustomerId = c(2, 5, 6), City = c(rep("Chicago", 2), rep("NewYorkCity", 1))) > df2 CustomerId City ... Read More

Why we should use set.seed in R?

Nizamuddin Siddiqui
Updated on 06-Jul-2020 14:58:52

6K+ Views

The use of set.seed is to make sure that we get the same results for randomization. If we randomly select some observations for any task in R or in any statistical software it results in different values all the time and this happens because of randomization. If we want to keep the values that are produced at first random selection then we can do this by storing them in an object after randomization or we can fix the randomization procedure so that we get the same results all the time.ExampleRandomization without set.seed> sample(1:10) [1] 4 10 5 3 1 6 ... Read More

How to make list of data frames in R?

Nizamuddin Siddiqui
Updated on 06-Jul-2020 14:57:34

276 Views

This can be done by using list function.Example> df1

Advertisements