Fibonacci Series
This Program generates Fibonnaci Series for a given number of times.
Output: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
[sourcecode language='java']
public class FibonnaciSeries {
/*
* Generates the Fibonnaci Series
*/
public void generateSeries(int num) {
int f1, f2 = 0, f3 = 1;
System.out.println(”fib(0) = ” + f2);
for (int i = 1; i <= num; i++) {
System.out.println("fib(" + i + ") = " + f3);
f1 = f2;
f2 = f3;
f3 = f1 + f2;
}
}
public static void main(String[] args) {
System.out.println("*****Fibonnaci Series*****");
FibonnaciSeries fb = new FibonnaciSeries();
fb.generateSeries(10);
}
}
[/sourcecode]
Highest Prime Number
Given a number this program generates the highest prime number.
Output: If the input is 25, the highest prime number close to 25 is 23. It prints 23.
[sourcecode language='java']
public class PrimeNumber {
/*
* Given a number, finds the highest prime number.
*/
public static int highestPrime(int n) {
int value = 1;
for (int i = 2; i <= n; i++) {
// System.out.println("n: " + n + " i: " + i + " mod: " + n%i);
if (i == n) {
value = n;
break;
}
if (n % i == 0) {
n--;
}
}
return value;
}
public static void main(String[] args) {
int value = highestPrime(25);
System.out.println("Prime:" + value);
}
}
[/sourcecode]
Triangle Printing
Given a number, this program prints the numbers in the right angle manner.
Output:
1
2 3
4 5 6
7 8 9 10
11 12 13 14
[sourcecode language='java']
public class TrianglePrinting {
/*
* Prints the numbers in the right angle manner.
*/
public static void trianglePrinting(int n) {
int counter = 0, i = 1;
while (i <= n) {
counter++;
for (int j = 0; j < counter; j++) {
if (i > n)
break;
System.out.print(i + ” “);
i++;
}
System.out.println();
}
}
public static void main(String[] args) {
trianglePrinting(14);
}
}
[/sourcecode]











please send me the java program of “prime number of Fibonacci series”
let us take e.g.
0, 1,1,2,3,5,8,13,………..
den prime number series will be- 3,5,13…………
amazing coding sir thanx
please send me th java programe “1 3, 2 4. 5 7, 6 8, 9 11, 10 12;”
sir, i want simple logic of prime number programs
what is fibonacci series
hi, i want a logic program like
1
121
1231
12341
please send array using java
wowwwwwwwwwwwwwwww
FibonacciSeries class would never compile , because of the blunders in the code
Hope u can the see double ‘n’ s used while creating a new instance of the class,
It becomes a minimal etiquette to check the code (run it in u r machine )
as many of the newbie’s may take as reference and copy the same code and try to run it
hope u take this in the +ve manner
This is the output generated by the Fibonacci Series Program.
It is 100% correct. Let me know what is the output u r getting.
Let’s consider v1= 5, v2 = 10, then v3 = 15 (i.e v1 + v2)
v4 = 25 (i.e. v3 + v4) there on…..
Fibonacci Series
*****Fibonacci Series*****
fib(0) = 0
fib(1) = 1
fib(2) = 1
fib(3) = 2
fib(4) = 3
fib(5) = 5
fib(6) = 8
fib(7) = 13
fib(8) = 21
fib(9) = 34
fib(10) = 55
Copy the same code that you have pasted ,u will get
FibonnaciSeries cannot be resolved
to a type
Copy the same code that you have pasted ,u will get
FibonnaciSeries cannot be resolved to a type error
because of the spelling mistakes as u r class name is
FibonacciSeries and u r instantiating a new object with
FibonnaciSeries fb = new FibonnaciSeries(); (which contains single n and double c’s)
So i wondered did u ever run in u r machine
Thanks for the correction. The program is updated.
the second program will also be modified to be divided by 3 because if you take 21 as an example if you divide it by 2 it will say its prime number thou its not.. its divided by 3 .. I think we also need to add a if dividing the number with three..
/* 1 3, 2 4, 5 7, 6 8, 9 11, 10 12 */
import java.io.*;
public class oddevenpair {
public static void main(String a[]) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print(”Enter Number : “);
int n = Integer.parseInt(br.readLine());
int odd[] = new int[2];
int eve[] = new int[2];
int o = -1, e = -1;
StringBuffer sb = new StringBuffer();
for(int i=1; i<=n; i++) {
if(i%2==0) {
e++;
eve[e] = i;
}
if(e==1) {
sb.append(eve[0] + ” ” + eve[1] + “, “);
e = -1;
}
if(i%2!=0) {
o++;
odd[o] = i;
}
if(o==1) {
sb.append(odd[0] + ” ” + odd[1] + “, “);
o = -1;
}
}
System.out.println(sb.delete(sb.length()-2, sb.length()-1).toString());
}
}
/*
1
121
1231
12341
*/
import java.io.*;
public class inseq{
public static void main(String a[]) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print(”Enter a Number : “);
int n = Integer.parseInt(br.readLine()); //Read the numeric input from console
for(int i=0; i<n; i++){
for(int j=0; j0) {
System.out.print(1);
}
System.out.println(”\n”);
}
}
}
please send the programs
1.display the factor numbers
2.display the prime number
3.display the 1 to 25 prime numbers
send me a fibonaci series program in prime number
program using fibonacci series in prime number
want a program in java for a pyramid of 5 like:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
HI i can do all types of pyramid programs !can u print a diamond in java
1
1 1
1 1
1 1
1 1
1 1
1
/* aprogram to display factors*/
import java.io.*;
public class inseq{
public static void main(String a[]) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print(”Enter a Number : “);
int n = Integer.parseInt(br.readLine());
int i,
for(i=1;i<=n;i++)
{
if(n%i==0)
{
System.out.print(i);
}
}
}
}
hi, i want a program like this
12345
1234
123
12
1
Hi, ccan I ask how can I output this:
25
1
20
15
3
10
4
5
5
Please, I realy need it. Please help me! T.T
input string=acasereeeeeeee
hi,can i ask how can I output this
9
e
Please, I realy need it. Please help me!
hi frns, can any one give the code to get the following output
1
2 3
4 5 6
7 8 9 10
11 12 13
14 15
16
Please send me the java program for Infix to postfix and prefix expression..
input string=acasereeeeeeee
>input string=acasereeeeeeee
>hi,can i ask how can I output this
>9
>e
>Please, I realy need it. Please help me!
see you mean to input a String
you need to input it.
//suppose s is String
int hn=0;
int c=0;
int i,j;
for(i=0;i<s.length();i++)
{
//remaining part
char ch=s.charAt(i);
//search for next now
for(j=0;j<s.length();j++)
{
char chr=s.charAt(j);
if(ch==chr) c++;
}
c–;
if(h<c){ h=c; //you have to take an
//int variable and v=i; as
//i forgot to take v in start.
}
}
System.out.println(s.charAt(v)); //remember v
System.out.println(h);
“hi frns, can any one give the code to get the following output
1
2 3
4 5 6
7 8 9 10
11 12 13
14 15
16
”
int c=1;
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j=1;i–)
{
for(j=1;j<=i;j++)
{
System.out.print(c+" ");
c++;
}
System.out.println();
}
i want to always need for this
hi,
i want to knw the logic for permutation of string… in lexicographic order
like for String abc its permutation shud be
abc
acb
bac
bca
cab
cba
hi,
i want to knw the logic for permutation of string… in lexicographic order
like for String abc its permutation shud be
abc
acb
bac
bca
cab
cba
Any one can give me the calculate programming codes without useing conditions,loopig,swith case & Ternary Operator ?
can u please help me for the code of this java problem:
i want to display this 2 3 4
1+2 +3 +4 =1+4+27+256=288
thanks
can u please help me for the code of this java problem:
i want to display this factorial
1+2 +3 +4 =1+4+27+256=288
thanks
SOLUTION:
1
1 2
1 2 3
1 2 3 4
….
import javax.swing.*;
public class NumAngle2 {
public static void main(String[] args) {
System.out.println(”This program prints numbers in the right angle manner.”);
String input = JOptionPane.showInputDialog(”Enter number?”);
int num = Integer.parseInt(input);
int counter = 1;
for(int i = 0; i < num; i++) {
counter++;
for(int j = 1; j < counter; j++) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
Hey guys I am from India and I guarantee you that this Fibonacci number series program will work:-
import java.io.*;
class fibonacci
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int num,ans1=1,ans2=0,ans3;
System.out.println(”Enter number”);
num=Integer.parseInt(br.readLine());
num=num-2;
System.out.print(ans2);
System.out.print(” “);
System.out.print(ans1);
System.out.print(” “);
while(num!=0)
{
ans3=ans1+ans2;
System.out.print(ans3);
System.out.print(” “);
ans2=ans1;
ans1=ans3;
num=num-1;
}
}
}
hi friendz
can anyone give me the code for the prog:
to accept a string from the user and change the beginning letter of every word with a CAPITAL letter.
/* 1
1 2 1
1 2 3 1
1 2 3 4 1
*/
import javax.swing.*;
public class OneAngle {
public static void main(String[] args) {
String input = JOptionPane.showInputDialog(”Enter num?”);
int n = Integer.parseInt(input);
int count = 0;
for(int i = 1; i <= n; i++) {
count++;
for(int j = 1; j 1) System.out.print(1);
System.out.println();
}
}
}
can you help me how to figure out this java problem.. here is the output..
***
* *
* *
* *
* *
***
___***
__*___*
_*_____*
_*_____*
__*___*
___***
Leave a Reply