Shriansh Kumar

Shriansh Kumar

211 Articles Published

Articles by Shriansh Kumar

Page 11 of 22

Java program to find common elements in three sorted arrays

Shriansh Kumar
Shriansh Kumar
Updated on 16-Aug-2024 2K+ Views

The common elements in three sorted arrays are those elements that occur in all three of them. In this article, we will learn how to find common elements from three sorted arrays in Java. An example of this is given as follows − Example Scenario: Input 1: arr1 = [1, 3, 5, 7, 9] Input 2: arr2 = [2, 3, 6, 7, 9] Input 3: arr3 = [1, 2, 3, 4, 5, 6, 7, 8, 9] Output: Common elements = 3 7 9 Here, arrays are data structure which stores a fixed-size sequential collection of elements of the same ...

Read More

Java program to multiply given floating point numbers

Shriansh Kumar
Shriansh Kumar
Updated on 16-Aug-2024 2K+ Views

Suppose two floating point numbers are given as operands and your task is to write a Java program to multiply the given numbers. To perform this operation, initialize two float values, multiply and store the result in another float type variable. Float is a datatype in Java which stores numbers with fractional part. Example Scenario: Input 1: num1 = 1.2 Input 2: num2 = 1.4 Output: product = 1.68 Using Multiplication Operator The multiplication operator is represented by asterisk sign (*). It is categorized under arithmetic operator in Java. It can be used to multiply float values ...

Read More

Java Program to get day of week as string

Shriansh Kumar
Shriansh Kumar
Updated on 16-Aug-2024 3K+ Views

Some applications that work on calendars require a day name to be displayed for features like scheduling tasks, events or reminders. For this purpose, Java provides various built-in classes and methods including LocalDate, Calendar and SimpleDateFormat. In this article, we will learn how to use these classes and methods in Java programs to find the day name of a week for a given date. Using LocalDate Class In this approach, we first find current date using LocalDate class and using its built-in method named getDayOfWeek(), we create a DayOfWeek Enum which can be converted to String to display day ...

Read More

Java program to find whether the given character is an alphabet or not

Shriansh Kumar
Shriansh Kumar
Updated on 05-Aug-2024 3K+ Views

For a character "ch", write a Java program to verify whether it lies between a and z (both small and capital). If it does it is an alphabet otherwise, not. Alphabets are the set of letters written to represent particular sounds in a spoken language like English. Example Scenario 1: Input: character = 'e'; Output: Yes given character is an alphabet Example Scenario 2: Input: character = '4'; Output: No given character is not an alphabet Using ASCII Values The term ASCII stands for American Standard Code for Information Interchange. Every English letters has an ASCII value ...

Read More

Java Program to convert string to byte

Shriansh Kumar
Shriansh Kumar
Updated on 01-Aug-2024 1K+ Views

Suppose you are given a String named "str". Now, your task is to write a Java program to convert the given string to Byte. String is a class in Java which stores sequence of characters within double quotes and Byte is a wrapper class of java.lang package which wraps value of byte datatype. Example Scenario: Input: String str = "65"; Output: res = 65 Using Byte.valueOf() Method The valueOf() method of Java Byte class is used to convert given string into its corresponding Byte object. It accepts a single numeric string as a parameter value and returns it as ...

Read More

Java Program to Check Whether a Number is Prime or Not

Shriansh Kumar
Shriansh Kumar
Updated on 01-Aug-2024 29K+ Views

Given a number, let's say N, write a Java program to check whether the given number is prime or not. Prime numbers are special numbers with only two factors 1 and that number itself, they cannot be divided by any other number. Example Scenario 1 Input: num = 1; Output: 1 is not a prime number Example Scenario 2 Input: num2 = 5; Output: 5 is a prime number 5 is divisible by 1 and 5 only Checking Prime Numbers using Factorization The naive approach to check a given number is prime or not is factorization. ...

Read More

Java Program to Check whether the input number is a Neon Number

Shriansh Kumar
Shriansh Kumar
Updated on 01-Aug-2024 1K+ Views

In this article, we will understand how to check whether the given input number is a neon number. A neon number is such a number whose sum of digits of square of the number is equal to the number itself. Example Scenario: Input: num = 9; Output: The given input is a neon number How to Check Neon Number in Java? To check a given input is a neon number in Java, use the below approaches − Using for loop Using while loop Using recursion Using ...

Read More

Java Program to compare dates if a date is after another date

Shriansh Kumar
Shriansh Kumar
Updated on 01-Aug-2024 2K+ Views

In Java, there are a few scenarios where we are required to work with the date and time such as while developing a calendar application, attendance management system in Java and checking age of two persons. Also, the date is a way of keeping track of our time as it is an integral part of our daily lives. Therefore, Java provides classes like Date and LocalDate to work with date and time. In this article, we will discuss how to compare and check if a date is after another or not. Example Scenario 1 Input: dateOne = "2023-01-20"; ...

Read More

Java String Concatenation with Other Data Types.

Shriansh Kumar
Shriansh Kumar
Updated on 01-Aug-2024 2K+ Views

In Java, string concatenation is the operation of joining two or more strings together. However, string concatenation can be performed with various primitive data types, not just with other strings. Two strings can be concatenated using concat() method of String class, but, to concatenate strings with other primitive data type you need to use the ‘+’ operator. The given data type will automatically converted to its string representation. Example Scenario: Input: String res = "Age: " + 45; Output: result = Age: 45 String Concatenation with int The int is a primitive datatype in Java which represents numeric data ...

Read More

Java Program to return the elements at the odd position in a list

Shriansh Kumar
Shriansh Kumar
Updated on 01-Aug-2024 988 Views

What is the Odd Position in a List? In Java, a List does not have predefined odd and even positions. However, if one considers the first position as index 0, then an odd position in the given List would be any index that is not divisible by 2. To determine if a position is odd, use the modulo operator (%).   How to Find Elements at Odd Position in a List? Below approaches are followed to find out the elements at the odd position in a list − By dividing index with 2 ...

Read More
Showing 101–110 of 211 articles
« Prev 1 9 10 11 12 13 22 Next »
Advertisements