Java program to create a singly linked list of n nodes and count the number of nodes17 Mar 2025 | 3 min read In this program, we need to create a singly linked list and count the nodes present in the list. ![]() To accomplish this task, traverse through the list using node current which initially points to head. Increment current in such a way that current will point to its next node in each iteration and increment variable count by 1. In the end, the count will hold the value which denotes the number of nodes present in the list. Algorithm
a. countNodes() will count the nodes present in the list:
a. display() will display the nodes present in the list:
Program:Output: Nodes of the singly linked list: 1 2 3 4 Count of nodes present in the list: 4 Next TopicJava Programs |
In this section, we will learn what is tech number and how can we find tech numbers through a Java program. Tech Number A number is called a tech number if the given number has an even number of digits and the number can be divided exactly into...
3 min read
In this section, we will discuss what is Armstrong number and also create Java programs to check if the given number is an Armstrong number or not. The Armstrong number program frequently asked in Java coding interviews and academics. Armstrong Number An Armstrong number is a positive...
5 min read
Java Convert char to String We can convert char to String in java using String.valueOf(char) method of String class and Character.toString(char) method of Character class. Java char to String Example: String.valueOf() method Let's see the simple code to convert char to String in java using String.valueOf() method. char c='S'; String s=String.valueOf(c); Let's...
1 min read
Java Program to find Largest Number in an Array We can find the largest number in an array in java by sorting the array and returning the largest number. Let's see the full example to find the largest number in java array. public class LargestInArrayExample{ public static int getLargest(int[]...
2 min read
The singly linked list is a linear data structure in which each element of the list contains a pointer which points to the element in the list. Each element in the singly linked list is called a node. Each node has two components: data...
5 min read
In this section, we will learn what is an emirp number and also create Java programs to check if the given number is emirp or not. The emirp number Java program frequently asked in Java coding tests to check the logic of the programmer. Emirp Number A number...
2 min read
Program to print the elements of an array in reverse order In this program, we need to print the elements of the array in reverse order that is; the last element should be displayed first, followed by second last element and so on. Above array in reversed...
2 min read
In this program, we need to replace all the spaces present in the string with a specific character. String: Once in a blue moon String after replacing space with '-': Once-in-a-blue-moon One of the approach to accomplish this is by iterating through the string to find spaces. If...
2 min read
Java Convert float to String We can convert float to String in java using String.valueOf() and Float.toString() methods. Scenario It is generally used if we have to display float value in textfield because everything is displayed as a string in form. 1) String.valueOf() The String.valueOf() is an overloaded method. It can...
1 min read
Java Program Number to Word In this section, we will create a Java program that converts the given number into words. For example, if the given number is 54,297 then the output should be Fifty-Four Thousand Two Hundred Ninety-Seven. Let's create a Java program for the same. NumberToWordExample1.java class...
9 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India