Found 34494 Articles for Programming

Java Program for Closest Prime Number

Mr. Satyabrata
Updated on 02-Jul-2024 09:35:01

916 Views

A prime number is a positive integer greater than 1 that is only divisible by 1 and itself. Prime numbers are an essential concept in mathematics and computer science. They are integers that are only divisible by 1 and themselves. Finding prime numbers is an important task in many algorithms, and there are several methods to determine if a number is prime. One such problem is finding the closest prime number to a given number. Problem Statement For a given number find the closest prime number by using Java programming language. Consider the following example - Input ... Read More

How to Read a File into an ArrayList in Java?

Mr. Satyabrata
Updated on 17-Aug-2023 17:45:16

2K+ Views

In Java, an ArrayList is a resizable array, which is implemented as part of the Java Collections Framework. It is a dynamic data structure that can hold any type of objects, including primitive types such as integers and characters. As per the problem statement we have to read a file into an ArrayList. First and foremost we will take the path of the file as input and then we will apply different method to read the file. Let's start! For instance Suppose the input file is “myfile.txt”. After reading the content of the file, the result ... Read More

How to Convert Timestamp to Date in Java?

Mr. Satyabrata
Updated on 20-Jun-2024 15:42:32

8K+ Views

In Java, Timestamp can be converted Date by using Date class. Date class is present in java.util package. The constructor of the Date class receives a long value as an argument. Since the constructor of the Date class requires a long value, we need to convert the Timestamp object into a long value using the getTime() method of the TimeStamp class. Let's deep dive into this article, to know how it can be done by using Java programming language. To show you with instance Suppose the timestamp is 06/01/2023. Then corresponding Date is “Fri Jan ... Read More

Python Program to Increment Numeric Strings by K

Aditya Varma
Updated on 17-Aug-2023 20:49:13

276 Views

A numeric string in Python is a string that represents a numerical value using digits, signs, and decimal points, allowing for mathematical operations and data processing. In this article, we will learn a python program to increment numeric strings by K. Example Assume we have taken an input list of strings. We will now increment the numeric strings in an input list by k using the above methods. Input inputList = ["10", "hello", "8", "tutorialspoint", "12", "20"] k = 5 Output ['15', 'hello', '13', 'tutorialspoint', '17', '25'] In the above list, 10, 8, 12 20 are the numeric ... Read More

Python Program to find the key of Maximum Value Tuples in a Dictionary

Aditya Varma
Updated on 17-Aug-2023 20:44:53

120 Views

Finding the key of the maximum value tuples in a python dictionary means identifying the key associated with the tuple that has the highest value among all the tuples in the dictionary, which can be useful for retrieving the most significant or relevant information from the data. Example Assume we have taken an input dictionary having values as tuples. We will now find the key of maximum value tuples in an input dictionary using the above methods. Input inputDict = {'hello': ("p", 2), 'tutorialspoint': ("c", 15), 'python': ("k", 8)} Output The key of the maximum value in a ... Read More

How to Convert Char to Int in Java?

Mr. Satyabrata
Updated on 17-Aug-2023 17:35:59

530 Views

In Java, smaller datatype can be converted to bigger datatype. Here, we will see how to convert char datatype to int datatype. The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65, 535 inclusive). The int data type is a 32-bit signed two's complement integer, which has a minimum value of -231 and a maximum value of 231-1. Let's deep dive into this article, to know how it can be done by using Java programming language. For instance Suppose the given ... Read More

Python Program to Find Most Common Elements Set

Aditya Varma
Updated on 17-Aug-2023 20:43:08

338 Views

In Python, a set is an unordered collection of unique elements, represented by {}. It allows efficient membership testing and eliminates duplicate values, making it useful for tasks such as removing duplicates or checking for common elements between sets. In this article, we will learn a python program to find the most common elements set. Methods Used The following are the various methods to accomplish this task: Using for loop and set.intersection() function Using list comprehension, max() and intersection() functions Demonstration Assume we have taken an input list containing sets. We will now get the most ... Read More

Python Program to find Maximum Scoring Word

Aditya Varma
Updated on 17-Aug-2023 20:40:54

78 Views

In Python, strings are a fundamental data type used to represent sequences of characters. They are enclosed in single quotes ('') or double quotes ("") and offer a wide range of operations and methods for manipulation Example Assume we have taken an input string. We will now find the maximum scoring word from an input string using the above methods. Input inputString = "hello tutorialspoint python users and learners" Output Resultant maximum scoring word from the input string: tutorialspoint In the above input string, the sum of characters' positional values of the word tutorialspoint is having the ... Read More

Python Program to Convert list of Dictionaries to Dictionary of Lists

Aditya Varma
Updated on 17-Aug-2023 20:36:00

246 Views

In Python, a dictionary is a built-in data structure that stores data in key-value pairs. It allows efficient retrieval and modification of values based on their corresponding keys. Each key in a dictionary must be unique, and it is associated with a specific value. A dictionary of lists is a dictionary where the values associated with each key are lists. This means that each key maps to multiple values, and those values are stored as elements within a list. On the other hand, a list of dictionaries is a list that contains multiple dictionaries as its elements. Each dictionary within ... Read More

Create a Matrix and Fill Primary Diagonal with 1 and Secondary Diagonal with 2

Mr. Satyabrata
Updated on 17-Aug-2023 17:33:03

205 Views

In Java, a matrix can be represented using a two-dimensional array. Matrices are used for storing and manipulating data that have a tabular structure. Matrices have several properties and operations associated with them, such as addition, subtraction, multiplication, transposition, and determinant calculation. As per the problem statement we have to Create a Matrix and Fill Primary Diagonal with 1 and Secondary Diagonal with 0. Let's start! For instance Suppose we have 4*4 matrix i.e. 4 rows and 4 columns. After performing the operation on matrix, the result will be: Enter the size of the matrix: ... Read More

Advertisements