Java Articles

Page 192 of 450

Check whether the String contains only digit characters in Java

Samual Sam
Samual Sam
Updated on 27-Aug-2024 2K+ Views

Introduction In this article, we'll explore how to check whether a given string contains only digits or a mix of digits and other characters in Java. We'll achieve this by using the String class and its matches() method. Problem Statement Given a string write a Java program to check whether it contains only digit characters. Input 1 4434 Output 1 String contains only digits! Input 2 5demo9 Output 2 String contains digits as well as other characters! Steps to check digit characters in String The following are the steps to check whether the String contains only digit characters in ...

Read More

Java program to calculate distance light travels

karthikeya Boyini
karthikeya Boyini
Updated on 27-Aug-2024 2K+ Views

In this article, we will demonstrate how to calculate the distance light travels in one year using Java. We will use the Demo class and the main method to perform this calculation. Speed of light: 186000Days = 365dist = speed * seconds Problem Statement Write a Java program to calculate the total distance that light travels in a year, given that the speed of light is 186, 000 miles per second. Output Light travels: 5865696000000 miles Steps to calculate distance light travels Following are the steps to calculate the distance light travels − Initialize the Demo class.Define ...

Read More

Java program to split a list into two halves

AmitDiwan
AmitDiwan
Updated on 27-Aug-2024 2K+ Views

In this article, we will understand how to split a list into two halves. A list is an ordered collection that allows us to store and access elements sequentially. It contains index-based methods to insert, update, delete, and search the elements. It can also have duplicate elements. We will be using different approaches to split a list into two halves − Problem Statement Write a Java program to split a list into two halves. As demonstrated below − Input  Input list :[Java, Python, JavaScript, Shell, Scala] Output The first half of the list is: [Java, Python] The second half of ...

Read More

Java program to subtract year from current date

Samual Sam
Samual Sam
Updated on 27-Aug-2024 2K+ Views

In this article, we will learn to subtract a year from the current date using Java. We will be using the Calender class of java.util package. Calendar class in Java is an abstract class that provides different methods to convert between a specific instant in time and a set of calendar fields such as HOUR, DAY_OF_MONTH, MONTH, YEAR, and so on. It is also used for manipulating the calender field. Steps to subtract year from current date Following are the steps to subtract year from current date − Import the Calendar class from the java.util package. ...

Read More

Java program to print Swastika by taking input from user

Saba Hilal
Saba Hilal
Updated on 27-Aug-2024 2K+ Views

Swastika is a religious symbol of Hinduism, Buddhism, and Jainism. In this article, we will learn to print Swastika by taking user input. Here, are three different approaches for making this design using Java. In all the approaches, the size of the Swastika is decided by the user. The user provides the input for the table or frame size. The Swastika is often used as an example to learn rows, columns, and tabular layout concepts using different languages including Java. Making Swastika using Java. Here, three different approaches are used to make this design using Java − ...

Read More

Java Naming Conventions

Ankitha Reddy
Ankitha Reddy
Updated on 22-Aug-2024 4K+ Views

All Java components require names. Names used for classes, variables and methods are called identifiers. The naming conventions for different Java components are as follows: Package Naming Convention Class Naming Convention Interfaces Naming Convention Method Naming Convention Constants Naming Convention Variables Naming Convention Quick Summary Package Naming Convention Naming conventions for Java packages typically involve using lowercase letters. It's common to use ...

Read More

Java Naming Conventions

Ankitha Reddy
Ankitha Reddy
Updated on 22-Aug-2024 4K+ Views

All Java components require names. Names used for classes, variables and methods are called identifiers. The naming conventions for different Java components are as follows: Package Naming Convention Class Naming Convention Interfaces Naming Convention Method Naming Convention Constants Naming Convention Variables Naming Convention Quick Summary Package Naming Convention Naming conventions for Java packages typically involve using lowercase letters. It's common to use ...

Read More

Java object creation of Inherited class

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

The constructor is something responsible for the object creation of a particular class in Java. Along with other functions of the constructor, it also instantiates the properties/instances of its class. In Java by default super() keyword is used as the first line of the constructor of every class, here the purpose of this method is to invoke the constructor of its parent class so that the properties of its parent get well instantiated before subclass inherits them and use. The point that should remember here is when you create an object the constructor is called but it is not mandatory that ...

Read More

Java program to find the percentage of uppercase, lowercase, digits and special characters in a String

Akshaya Akki
Akshaya Akki
Updated on 22-Aug-2024 2K+ Views

This article will teach us how to transform a string into an array of characters in order to examine its composition. Next, we shall categorize every character as a numeric, special character, lowercase letter, or uppercase letter. The methods of Java Character class will be used to do this. For each group (uppercase, lowercase, numbers, and special characters), we'll compute the percentage and show the results.  isUpperCase() : The Java Character isUpperCase() method determines if a character is an uppercase character or not. isLowerCase() : The Java Character isLowerCase() method determines if a character is a lowercase character or not. isDigit() : The ...

Read More

Java program to print number series without using any loop

AmitDiwan
AmitDiwan
Updated on 22-Aug-2024 2K+ Views

In this article, we will learn how to print a sequence of numbers in Java, ranging from 0 to 15. To do this, we'll use recursion rather than using loops like for loop or while loop. Recursion is a programming technique where a method calls itself to perform a sub-operation as necessary. Problem Statement Write a Java program to print Number series without using any loop Output The numbers without using a loop have been printed below0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, Java program to print number series without using ...

Read More
Showing 1911–1920 of 4,496 articles
« Prev 1 190 191 192 193 194 450 Next »
Advertisements