Programming Articles

Page 171 of 2544

Java program to get random letters

karthikeya Boyini
karthikeya Boyini
Updated on 05-Sep-2024 2K+ Views

In this article, we will learn to write a program in Java to get the random letters in both lowercase and uppercase. We will be using Random class from java.util package.The program will first create random lowercase letters by selecting them from the alphabet, and then it will generate random uppercase letters in a similar way.  Problem Statement Write a program in Java to get the random letters both uppercase and lower case. Below is the demostration − Output Lowercase random letters...dlhjsUppercase random letters...BKIZN Step to get random letters Following are the steps to get the random letter using Java ...

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

Java program to find 2 elements in the array such that difference between them is largest

Rushi Javiya
Rushi Javiya
Updated on 30-Aug-2024 641 Views

In this problem, we will find two array elements such that the difference between them is maximum using Java. We can make a pair of each element and find the difference between the elements of each pair. After that, we can take a pair whose element has a maximum difference. Another approach is to sort the array and take the largest and smallest elements from the array. Problem statement  We have given an array containing the integer values. We need to find two array elements to maximize the difference between them. Input 1 array[] = { 50, 10, 30, ...

Read More
Showing 1701–1710 of 25,433 articles
« Prev 1 169 170 171 172 173 2544 Next »
Advertisements