Basic Programs

Java Program to find the IP address of the Machine

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 […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

Java program to print Fibonacci sequence Recursive & Non Recursive

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 […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

Java program to display triangle 0 10 101 0101

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"); } } }

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

Java program to display triangle 1 23 456 78910

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 = […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

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

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–; […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

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

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 […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

Java program to demonstrate switch case

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 […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

Java program to find whether no. is palindrome or not

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 […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone