Java Articles

Page 73 of 450

Java program to check occurrence of each character in String

Chandu yadav
Chandu yadav
Updated on 05-Sep-2024 26K+ Views

To find the occurrence of each character in a string we can use the Map utility of Java. In Map a key cannot be duplicated so make each character of the string a key of Map and provide the initial value corresponding to each key as 1 if this character is not inserted in Map before. Now when a character repeats during insertion as a key in Map increases its value by one. Continue this for each character until all characters of the string get inserted. Problem Statement Write a program in Java to check the occurrence of each character in ...

Read More

Java program to check occurrence of each character in String

Chandu yadav
Chandu yadav
Updated on 05-Sep-2024 26K+ Views

To find the occurrence of each character in a string we can use the Map utility of Java. In Map a key cannot be duplicated so make each character of the string a key of Map and provide the initial value corresponding to each key as 1 if this character is not inserted in Map before. Now when a character repeats during insertion as a key in Map increases its value by one. Continue this for each character until all characters of the string get inserted. Problem Statement Write a program in Java to check the occurrence of each character in ...

Read More

Java program to find sum of natural numbers using while loop

Shiva Keerthi
Shiva Keerthi
Updated on 05-Sep-2024 734 Views

The sum of natural numbers can be calculated using different Iterative Statements in Programming Languages. Iterative Statements are statements that execute a particular set of code lines until the condition in the loop statement fails. In this article, we will discuss how to calculate the sum of natural numbers using a while-loop which is an iterative statement in Java. Sum of Natural Numbers The sum of natural numbers generally indicates the total sum of elements from 1 to n. Mathematically it can be represented as follows Sum of n Natural Numbers = 1+2+3+.........+(n-2) + (n-1) + n ...

Read More

Java program to find sum of even factors of a number

AmitDiwan
AmitDiwan
Updated on 05-Sep-2024 1K+ Views

In this article we’ll find the sum of even factors of a given number using Java. We’ll start by checking if the number is even, then identify all of its factors, sum up those that are even, and finally display the result. Problem Statement Write a Java program to find the sum of even factors of a number. Below is the demostration of the same − Input num=16 Ouput The sum of even factors of the number is 30 Steps to find sum of even factors of a number Following are the steps to find sum of even factors of a number ...

Read More

Java program to multiply long integers and check for overflow

Samual Sam
Samual Sam
Updated on 02-Sep-2024 2K+ Views

To check for Long overflow, we need to check the Long.MAX_VALUE with the multiplied long result, Here, Long.MAX_VALUE is the maximum value of the Long type in Java. Let us see an example wherein long values are multiplied and if the result is more than the Long.MAX_VALUE, then an exception is thrown. Steps to multiply long integers and check for overflow Following are the steps to multiply long integers and check for overflow in Java − Initialize long values by defining two long integers, val1 and val2. Multiply val1 and val2 to ...

Read More

Java sql.Time valueOf() method with example

Vikyath Ram
Vikyath Ram
Updated on 02-Sep-2024 2K+ Views

In this program, we'll demonstrate how to insert and retrieve records from a MySQL database using JDBC . Specifically, we'll focus on how to convert a time value from a String format into a java.sql.Time object using the valueOf() method. This allows us to store time values in a database and retrieve them accurately. Time time = Time.valueOf("time_string"); Steps to Use sql.Time valueOf() Method Following are the steps to use sql.Time valueOf() method − Import all the useful classes. Register the Driver by loading the MySQL JDBC driver. ...

Read More

Java program to get the beginning and end date of the week

Krantik Chavan
Krantik Chavan
Updated on 30-Aug-2024 2K+ Views

In this article, we'll explore how to determine the start and end dates of a week using Java. Specifically, we'll write a program that takes a given date and calculates the Monday and Sunday of that week.  Problem Statement Write a Java program to find the beginning (Monday) and end (Sunday) dates of the week for a given date. Input Date = 2019-04-16 Output Start of the Week = 2019-04-15End of the Week = 2019-04-21 Steps to calculate week's start and end dates Following are the steps to get the beginning and end date of the week − ...

Read More

Java program to determine when a Frame or Window is closing

Chandu yadav
Chandu yadav
Updated on 30-Aug-2024 2K+ Views

In this article, we will learn to determine when a Frame or Window is closing in Java. We will create a simple window in Java Swing titled "Demo". It displays styled text (italic, black on orange) using a text pane inside a scrollable area. The program also listens for window-closing events, printing a message when you close it. This basic example is how to build a GUI with text styling and event handling.Steps to determine when a Frame or Window is closing Following are the steps to determine when a Frame or Window is closing in Java − ...

Read More

Java program to find the sum of a series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!

AmitDiwan
AmitDiwan
Updated on 30-Aug-2024 1K+ Views

In this program, we'll compute the sum of the series 1/1! + 2/2! + 3/3! + ... + n/n! using Java. This involves calculating factorials and summing the results of each term divided by its factorial. We'll use Java's basic arithmetic, loop control, and built-in classes to achieve this.Problem StatementWrite a Java program to calculate the sum of the series 1/1! + 2/2! + 3/3! + ... + n/n! and print the result.Steps to find the sum of a seriesFollowing are the steps to find the sum of a series −Import necessary classes from java.io and java.lang package.Initialize variables for the sum and ...

Read More

Java program to find cube root of a number using binary search

Shiva Keerthi
Shiva Keerthi
Updated on 30-Aug-2024 1K+ Views

The cube root of a number is an integer value when multiplied by itself thrice, giving the original number. In this article, we are going to write a Java program to find the cube root of a number using binary search. Finding the cube root of a number is one of the applications of the binary search algorithm. We will discuss in detail how we calculate the cube root using a binary search algorithm in Java. Problem Statement Write a Java program to find the cube root of a number using Binary Search − Input 1 64 Output 1 4 ...

Read More
Showing 721–730 of 4,496 articles
« Prev 1 71 72 73 74 75 450 Next »
Advertisements