# Java

## Java Program to find the IP address of the Machine

Here is a simple Java Program to find the IP address of the Machine. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16   import java.util.*; import java.lang.*; import java.net.*;   public class GetOwnIP { public static void main(String args[]) { try{ InetAddress ownIP=InetAddress.getLocalHost(); System.out.println("IP of my system […]

## Java program to print Fibonacci sequence Recursive & Non Recursive

The Fibonacci sequence is defined by the following rule. The first 2 values in the sequence are 1, 1. Every subsequent value is the sum of the 2 values preceding it. Write a Java program that uses both recursive and non-recursive functions to print the nth value of the Fibonacci sequence. 1 2 3 4 […]

## Java program to prints all real solutions to the quadratic equation ax2+bx+c = 0

Write a Java program that prints all real solutions to the quadratic equation ax2+bx+c = 0. Read in a, b, c and use the quadratic formula. If the discriminant b2-4ac is negative, display a message stating that there are no real solutions. 1 2 3 4 5 6 7 8 9 10 11 12 13 […]

## Java program to display triangle 1 24 369 481216

/* Display Triangle as follow 1 2 4 3 6 9 4 8 12 16 … N (indicates no. of Rows) */ class Output3{ public static void main(String args[]){ int n = Integer.parseInt(args[0]); for(int i=1;i

## Java program to display triangle 0 10 101 0101

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 /* Display Triangle as follow 0 1 0 1 0 1 0 1 0 1 */ class Output2{ public static void main(String args[]){ for(int i=1;i<=4;i++){ for(int j=1;j<=i;j++){ System.out.print(((i+j)%2)+" "); } System.out.print("\n"); } } }

## Java program to display triangle 1 23 456 78910

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 /* Display Triangle as follow : BREAK DEMO. 1 2 3 4 5 6 7 8 9 10 … N */ class Output1{ public static void main(String args[]){ int c=0; int n = […]

## Java program to find average of consecutive N Odd no. and Even no.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 class EvenOdd_Avg{ public static void main(String args[]){ int n = Integer.parseInt(args[0]); int cntEven=0,cntOdd=0,sumEven=0,sumOdd=0; while(n > 0){ if(n%2==0){ cntEven++; sumEven = sumEven + n; } else{ cntOdd++; sumOdd = sumOdd + n; } n–; […]

## Java program to generate Harmonic Series 1 + 1/2 + 1/3 + 1/4 + 1/5

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 /* Write a program to generate Harmonic Series. Example : Input – 5 Output – 1 + 1/2 + 1/3 + 1/4 + 1/5 = 2.28 (Approximately) */ class HarmonicSeries{ public static void main(String args[]){ int num = Integer.parseInt(args[0]); double […]

## Java program to demonstrate switch case

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 […]

## Java program to find whether no. is palindrome or not

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 /* Write a program to find whether no. is palindrome or not. Example : Input – 12521 is a palindrome no. Input – 12345 is not a palindrome no. */ class Palindrome{ public static void […]