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
Month: March 2022
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
Program to Add two Binary Numbers
Example: Adding binary numbers in Java In this program we are using Scanner to get the input from user (user enters the two binary numbers that we need to add) and then we are adding them bit by bit using while loop and storing the result in an array. Output:
Program to check Even or Odd number
Output 1: Output 2:
Program to Add two Numbers
Here we will see two programs to add two numbers, In the first program we specify the value of both the numbers in the program itself. The second programs takes both the numbers (entered by user) and prints the sum. First Example: Sum of two numbers Output: Second Example: Sum of two numbers using Scanner… Continue reading Program to Add two Numbers
Capitalize first character of each word
Java program to make the first letter of a String capital Output In the example, we have converted the first letter of the string name to upper case. Example 2: Convert every word of a String to uppercase Output Here, we have created a string named message we converted the string into a char array we access every element of… Continue reading Capitalize first character of each word
Create random strings
Java program to generate a random string Output In the above example, we have first created a string containing all the alphabets. Next, we have generated a random index number using the nextInt() method of the Random class. Using the random index number, we have generated the random character from the string alphabet. We then used the StringBuilder class to append… Continue reading Create random strings
Check if a String is Numeric
Check if a string is numeric Output In the above program, we have a String named string that contains the string to be checked. We also have a boolean value numeric which stores if the final result is numeric or not. To check if the string contains numbers only, in the try block, we use Double‘s parseDouble() method to convert the string to a Double. If it… Continue reading Check if a String is Numeric
Calculate simple interest
Calculate Simple Interest in Java Output In the above example, we have used the Scanner class to take principal, rate, and time as input from the user. We then use the formula of simple interest to compute the simple interest.