Find Area and Perimeter of Rectangle Using Class Concept in Java

Shiva Keerthi
Updated on 31-May-2024 16:30:49

8K+ Views

Java Language is one of the most used popular object - oriented programming language in present world. Class concept is one of the most important feature in Object - oriented languages. A Class is a like a blue print of an object. For example, when we want to build a house we first create a blue print of the house in other words we create a plan showing how we are going to build the house. Based on the plan we can create a number of houses. Similarly using class, we can create a number of objects. A class ... Read More

Count Letters in a String in Java

karthikeya Boyini
Updated on 31-May-2024 16:23:29

21K+ Views

Let’s say we have the following string, that has some letters and numbers.String str = "9as78";Now loop through the length of this string and use the Character.isLetter() method. Within that, use the charAt() method to check for each character/ number in the string.for (int i = 0; i < str.length(); i++) {    if (Character.isLetter(str.charAt(i)))    count++; }We have set a count variable above to get the length of the letters in the string.Here’s the complete example.Example Live Demopublic class Demo {    public static void main(String []args) {       String str = "9as78";       int count ... Read More

Concatenate Two Lists in Java

Bharti Kumari
Updated on 31-May-2024 16:15:26

10K+ Views

Introduction In Java, a list is an ordered collection of elements that allows duplicates. Sometimes, we may need to combine two lists into one list. Concatenating two lists means joining the elements of the two lists to form a new list containing all the elements of both lists. There are various ways to concatenate two lists in Java, including using loops, streams, and built-in methods. In this context, we will explore different approaches to concatenate two lists in Java. One approach is to use the addAll() method provided by the List interface. This method adds all the elements of one ... Read More

Convert ASCII Code to String in Java

karthikeya Boyini
Updated on 31-May-2024 15:34:30

18K+ Views

To convert ASCII to string, use the toString() method. Using this method will return the associated character.Let’s say we have the following int value, which works as ASCII for us.int asciiVal = 89;Now, use the toString() method.String str = new Character((char) asciiVal).toString();Example Live Demopublic class Demo {    public static void main(String []args) {       int asciiVal = 87;       String str = new Character((char) asciiVal).toString();       System.out.println(str);    } }OutputW

Implement RSA Algorithm in Java

Shubham Vora
Updated on 31-May-2024 15:28:42

6K+ Views

The RSA name is given by their inventors which is used to encrypt the text with high security. The RSA technique is one of the most used techniques to encrypt text, as it is the asymmetric encryption algorithm. It encrypts the text by utilizing the mathematical properties of the prime numbers. In the RSA algorithm, the sender and receiver have private keys. Also, a common public key exists, which the sender shares with the receiver. The sender encrypts the plain text using their own public and private key, and the receiver decrypts the message using their private and public ... Read More

Find Common Elements Between Two Arrays in Java

Shiva Keerthi
Updated on 31-May-2024 15:06:05

12K+ Views

We can use different approaches in Java to Find Common Elements between two arrays. We will discuss the approaches, including the basic steps involved, and provide the necessary code to achieve our goal. Whether you are a beginner or an experienced Java programmer, this article will provide you with the tools and knowledge necessary to solve this common programming problem. In this article, we will learn different ways of finding the common elements between two arrays. Examples for Common Elements Between Two Arrays: Example 1: Input: array1 = {4, 2, 3, 1, 6} array2 = {6, 7, 9, ... Read More

Java Menu Driven Program to Check Character Type

Mr. Satyabrata
Updated on 31-May-2024 14:47:53

12K+ Views

In this article, we will see a menu driven program to check if the entered character is number, string or special character by Java programming language. We will be implementing the application using a switch case. To show you some instances  Instance-1 Suppose the entered character is ‘a’ then the output should be “Entered character is a String”. Instance-2 Suppose the entered character is ‘1’ then the output should be “Entered character is a number”. Instance-3 Suppose the entered character is ‘$’ then the output should be “Entered character is a Special character”. Syntax To check whether ... Read More

Java Tricky Output Questions

Way2Class
Updated on 31-May-2024 14:14:28

11K+ Views

Java Tricky Output Questions that are difficult to answer call for more work to be put into them. We will fall short if we attempt to respond to a challenging topic using common sense since such questions need specialized understanding. The majority of challenging java problems are based on perplexing ideas like loops, multi-threading, overloading, overriding, etc. Even when a question isn’t particularly challenging, we occasionally have trouble solving it. Despite the fact that the answer to the question is straightforward, we occasionally write code carelessly. Even if we don’t know the solution, we can still use analytical thinking ... Read More

Handle Divide by Zero and Multiple Exceptions in Java

Shiva Keerthi
Updated on 31-May-2024 14:07:14

11K+ Views

Exceptions are the unusual events which disrupt the normal flow of execution of a program. When an exception occurs an object called exception object is generated, which contains details of exception like name, description, state of program. In this section, we are going to write a java program to handle divide by zero exception and how to handle multiple exceptions. Types of Exceptions− There are three types of exceptions − Checked exception − Checked exceptions are compile time exceptions i.e, they are checked during compilation of program.These cannot be ignored and must be handled by the programmer. ... Read More

Extract Digits from a Given Integer in Java

Rushi Javiya
Updated on 31-May-2024 14:02:14

20K+ Views

In Java programming, there are scenarios where we need to extract individual digits from an integer for further manipulation or analysis. This tutorial will guide you through the process of extracting digits from a given integer using Java. Syntax while (num > 0) { int digit = num % 10; System.out.println(digit); num = num / 10; } The above is the syntax to extract digits from an integer in Java. We keep extracting the last digit by taking the remainder of the number with 10. We divide the number by 10 until it ... Read More

Advertisements