Java program to print Fibonacci sequence Recursive & Non Recursive

Monday, February 7th, 2011  »  Posted By  »  Total 8 Comments

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

Monday, February 7th, 2011  »  Posted By  »  Total 2 Comments

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

Saturday, February 5th, 2011  »  Posted By  »  Total 1 Comment

/* 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

Saturday, February 5th, 2011  »  Posted By  »  Total 5 Comments

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

Saturday, February 5th, 2011  »  Posted By  »  Total 3 Comments

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.

Saturday, February 5th, 2011  »  Posted By  »  Total 0 Comment

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

Saturday, February 5th, 2011  »  Posted By  »  Total 6 Comments

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

Saturday, February 5th, 2011  »  Posted By  »  Total 2 Comments

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

Saturday, February 5th, 2011  »  Posted By  »  Total 21 Comments

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

Java program to find whether given no. is Armstrong or not

Saturday, February 5th, 2011  »  Posted By  »  Total 3 Comments

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 given no. is Armstrong or not. Example : Input – 153 Output – 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */ class Armstrong{ public […]

Question and Answer
C/C++ Unix & Linux Wordpress
Source codes
C C++ Java

Free email signup

Email: