Programming Articles

Page 1915 of 2547

Convert All Lowercase Text of a File into Uppercase in Java?

Mr. Satyabrata
Mr. Satyabrata
Updated on 01-Mar-2023 3K+ Views

In this article we are going to change all lower-case text to upper-case text in a file in java. Suppose the text file contains the following data − “Merry and Jack are studying.” Then after updating the text file with specific value the result will be − “MERRY AND JACK ARE STUDYING.” This modification is done with the help of toUpperCase() Method. It belongs to the String class in java. Let’s deep dive into this article, to know how it can be done by using Java programming language. To show you some instances Instance-1 Suppose the original content of the ...

Read More

Haskell Program to create a simple recursive function

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 2K+ Views

In this article, we are going to understand how to create a simple function in Haskell using user-defined function. Here, the user-defined recursive functions are defined that will contain base case and recursive case. Then, these functions are being called recursively by passing the argument to it. In all the examples, we are going to define certain functions to perform certain tasks. All these functions include, base and recursive cases. The function defined includes factorial, fibonacci, sumList, etc. Algorithm Step 1 − The user defined recursive function is defined with base and recursive case. Step 2 − ...

Read More

Haskell Program to return multiple values from the function

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 2K+ Views

In Haskell, we can return multiple values from the function by using user-defined function along with tuple, custom data type and Maybe data type. In the first example, we are going to use (myFunction = ("Hello, World!", 42)) and in the second example, we are going to use (data MyData = MyData { stringValue :: String, intValue :: Int }). And in third example, we are going to use, (myFunction :: Maybe (String, Int)). Method 1: Using Tuple In this method, a function can return multiple values by using a tuple. A tuple is a data structure that holds multiple ...

Read More

Haskell Program to return a string from the function

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 1K+ Views

In this article, we are going to learn how to return a string from a function using user-defined function along with record syntax and let binding. In the first example, we are going to use (myFunction = "Hello, World!") function and in the second example, we are going to use (myFunction = stringValue myData). And in third example, we are going to use let binding, (myFunction = let str = "Using let binding!" in str). Method 1: Returning a string from the user-defined function In this method, the user-defined functions are defined that will contain the function definition and return ...

Read More

Haskell Program to pass a string to the function

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 599 Views

This article will help us learn how to pass a string to the function in Haskell with identity function and lambda expression. In the first example, we are going to use (myFunction inputString = inputString) function and in the second example, we are going to use (myFunction = id). And in third example, we are going to use lambda expression, (myFunction = \inputString -> inputString). Method 1: Passing a string to the user-defined function In this method, the user-defined functions are defined that will contain the function definition with some returning value and is being called by passing a string ...

Read More

Haskell Program to return an array from the function

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 683 Views

This article will help us learn how to return an array from the function in haskell using user-defined function along with list comprehension and recursion. In the first example, we are going to use (show (getArray)) function and in the second example, we are going to use (getArray n = [x | x [Int] getArray n = [x | x Int) -> [Int] -> [Int] getArray f xs = map f xs main :: IO () main = do putStrLn (show (getArray (*2) [1, 2, 3, 4, 5])) Output [2, 4, 6, 8, ...

Read More

Haskell Program to pass an array to the function

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 857 Views

In Haskell, we will pass an array to the function by using user-defined functions. In all the examples, we are going to pass an array to the user-defined functions to perform the certain tasks. These functions can be sumArray, maxArray, minArray, countEvens, etc. In this method, the user-defined functions are created that will contain the function definition with some returning value and is being called by passing an array as argument to it. Algorithm Step 1 − The user defined function is defined by writing its definition with a return value. Step 2 − Program execution will ...

Read More

Haskell Program to create a function with arguments and a return value

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 888 Views

In this article, we are going to understand how to create a function with argument and a return value in Haskell using a user-defined function. The user-defined functions are defined that will contain the function definition with some returning value and is being called by passing desired arguments to it. These functions perform various operations as per the definition. In all the examples, we are going to define user-defined functions to perform certain tasks that will return some value and are passed with some arguments like, add, mult, maxOfTwo and other functions. Algorithm Step 1 − The user ...

Read More

Haskell Program to calculate the base 10 logarithm of the given value

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 676 Views

This tutorial will help us in calculating the base 10 logarithm of the given value. A logarithm is a mathematical function that calculates the power to which a number (called the base) must be raised to produce a given value. The base 10 logarithm, is a logarithm in which the base is 10. Method 1: Using Internal Functions In this method, we are going to use build-in log and log base function to calculate bas 10 log of a given number. Algorithm Step 1 − The Prelude library is imported to use log functions. Step 2 − ...

Read More

Haskell Program to calculate the base 2 logarithm of the given value

Akhil Sharma
Akhil Sharma
Updated on 01-Mar-2023 1K+ Views

In Haskell, the logarithm is a mathematical function that calculates the power to which a number (called the base) must be raised to produce a given value. The base 2 logarithm, also known as binary logarithm, is a logarithm in which the base is 2. For example, the base 2 logarithm of 8 is 3, because 2 to the power of 3 equals 8 (2^3 = 8). Method 1: Using logBase function In this method, the log function takes a value of type Double and returns the base 2 logarithm of that value, which is also of type Double. The ...

Read More
Showing 19141–19150 of 25,466 articles
Advertisements