Found 33676 Articles for Programming

Java program for recursive Bubble Sort

AmitDiwan
Updated on 27-Aug-2024 18:48:46

2K+ Views

In this article, we will learn to implement Bubble Sort using recursion in Java. Our goal is to understand how recursion can be applied to the Bubble Sort algorithm to achieve the same sorting effect as its iterative counterpart. Problem Statement Write a Java program to sort an array of integers using the recursive approach of Bubble Sort. Input my_arr[] = {45, 67, 89, 31, 63, 0, 21, 12} Output The array after implementing bubble sort is[0, 12, 21, 31, 45, 63, 67, 89] Bubble Sort Algorithm Bubble sort algorithm is a simple sorting algorithm to sort elements. ... Read More

Java program to calculate area of a tetrahedron

Alshifa Hasnain
Updated on 26-Feb-2025 19:36:26

475 Views

In this article, we will learn to calculate the area of a Tetrahedron using Java. A tetrahedron is a type of polyhedron that consists of four triangular faces. What is a tetrahedron? A tetrahedron is a three-dimensional polyhedron with four triangular faces, six edges, and four vertices. If all its faces are equilateral triangles, it is called a regular tetrahedron. The surface area of a regular tetrahedron can be calculated using the formula − 𝐴 = sqrt{3} . s^2 Where A is the surface area, where s is the length of a side of the tetrahedron. Calculating the Area of ... Read More

Java Program for array rotation

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

594 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

1K+ 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

200 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

800 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

531 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

848 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

Advertisements