Author: misamaliraza94
-
Program to calculate area of Triangle
Here we will see how to calculate area of triangle. We will see two following programs to do this:1) Program 1: Prompt user for base-width and height of triangle.2) Program 2: No user interaction: Width and height are specified in the program itself. Program 1: Output: Program 2: Output:
-
Program to calculate area of Square
In this tutorial we will learn how to calculate area of Square. Following are the two ways to do it: 1) Program 1: Prompting user for entering the side of the square2) Program 2: Side of the square is specified in the program’ s source code. Program 1: Output: Program 2: Output:
-
Program to Calculate Area of Rectangle
In this tutorial we will see how to calculate Area of Rectangle. Program 1:User would provide the length and width values during execution of the program and the area would be calculated based on the provided values. Output: Program 2:In the above program, user would be asked to provide the length and width values. If you…
-
Program to get input from user
In this tutorial we are gonna see how to accept input from user. We are using Scanner class to get the input. In the below example we are getting input String, integer and a float number. For this we are using following methods:1) public String nextLine(): For getting input String2) public int nextInt(): For integer input3)…
-
Program to get IP address
In this example we are gonna see how to get IP address of a System. The steps are as follows: 1) Get the local host address by calling getLocalHost() method of InetAddress class.2) Get the IP address by calling getHostAddress() method. Output:
-
Program to read integer value from the Standard Input
Example: Program to read the number entered by user We have imported the package java.util.Scanner to use the Scanner. In order to read the input provided by user, we first create the object of Scanner by passing System.in as parameter. Then we are using nextInt() method of Scanner class to read the integer. If you are new to Java…
-
Java program to check prime number
The number which is only divisible by itself and 1 is known as prime number, for example 7 is a prime number because it is only divisible by itself and 1.This program takes the number (entered by user) and then checks whether the input number is prime or not. The program then displays the result. If…
-
Program to display first 100 prime numbers
Program to display first n prime numbers Output: Program to display first 100 prime numbersTo display the first 100 prime numbers, you can either enter n value as 100 in the above program OR write a program like this: Output:
-
Program to Reverse a String using Recursion
Example 1: Program to reverse a string Output: Example 2: Program to reverse a string entered by user Output:
-
Program to check palindrome string using recursion
Program: Check whether String is palindrome using recursion Output: Output 2: