Program to Sort an Array in Ascending Order In this program, user is asked to enter the number of elements that he wish to enter. Based on the input we have declared an int array and then we are accepting all the numbers input by user and storing them in the array. Once we have all the… Continue reading Program to Sort an Array in Ascending Order
Program to sum the elements of an array
n this tutorial we will see how to sum up all the elements of an array. Program 1: No user interaction Output: Program 2: User enters the array’s elements Output:
Program to reverse the Array
Program to reverse the array Output:
Program to perform Bubble Sort on Strings
Bubble Sort on Strings example In the following example we have stored the strings in a String array and we are using nested for loops to compare adjacent strings in the array, if they are not in order we are swapping them using a temporary string variable temp. Here we are using compareTo() method to compare the adjacent Strings. Output:
Program to reverse words in a String
Program to reverse every word in a String using methods In this Program, we first split the given string into substrings using split() method. The substrings are stored in an String array words. The program then reverse each word of the substring using a reverse for loop. Output:
Program to find duplicate Characters in a String
This program would find out the duplicate characters in a String and would display the count of them. Output:
Convert Char To String and a String to char
rogram to convert char to String We have following two ways for char to String conversion.Method 1: Using toString() methodMethod 2: Usng valueOf() method Output: Converting String to Char We can convert a String to char using charAt() method of String class. Output:
Program to check Leap Year
Program to check whether the input year is leap or not Here we are using Scanner class to get the input from user and then we are using if-else statements to write the logic to check leap year. To understand this program, you should have the knowledge of following concepts of Core Java Tutorial:→ If-else statement→ Read input number in… Continue reading Program to check Leap Year
Program to Multiply Two Numbers
Program to read two integer and print product of them This program asks user to enter two integer numbers and displays the product. To understand how to use scanner to take user input, checkout this program: Program to read integer from system input. Output:
Program to Add Two Complex Numbers
Adding two complex numbers in Java In this program we have a class ComplexNumber. In this class we have two instance variables real and img to hold the real and imaginary parts of complex numbers. We have declared a method sum() to add the two numbers by adding their real and imaginary parts together. The constructor of this class is used for… Continue reading Program to Add Two Complex Numbers