Fibonacci Sequence — Set 2 Program No.2
/**
* @(#)fibonacci.java
* Program Number 2 >> Set 2
* Submitted by Neil John C. Basan
* Submitted to Mr. Rico E. Nonles
* 12.11.08
*/
import java.io.*;
class fibonacci
{
public static void main (String[] args) throws IOException
{
int nput, i, fibo1, fibo2, fibo3;
BufferedReader inputFromtheUser = new BufferedReader (new InputStreamReader (System.in));
String element = new String();
do
{
fibo1 = 0;
fibo2 = 1;
fibo3 = 1;
System.out.print(“Enter an Integer: “);
nput = Integer.parseInt(inputFromtheUser.readLine());
if (nput45) // prohibits the user from inputting less than 2
System.out.print(“Input must be above 2 and below 46″);
else if (nput==2)
System.out.print(” “+fibo2+” “+fibo3);
else
{
System.out.print(” “+fibo2+” “+fibo3);
for(i=3; i<=nput;i++) // loop until the user input
{ fibo1 = fibo2 + fibo3; //add the two numbers following the first fibonacci
System.out.print(” “+fibo1);
fibo3 = fibo2; //update the next fibonacci sequence to next number
fibo2 = fibo1; //update the next fibonacci sequence to previous number
}
}
System.out.print(“\nWould you like to perform a test? (y/n): “);
String firstAnswer = inputFromtheUser.readLine();
// —————————————————————-
// firstAnswer is NOT equal to “yes” and NOT equal to “y”,
// so we exit the program.
// —————————————————————-
if( ! firstAnswer.equalsIgnoreCase(“yes”) && ! firstAnswer.equalsIgnoreCase(“y”))
break;
}while(true);
}
}
Visual Basic 6.0 Tutorial
http://people.revoledu.com/kardi/
http://en.allexperts.com/q/Visual-Basic-1048/
Do While Loop with Yes or No in Java
String element = new String();
do{
System.out.print(“\nWould you like to perform a test? (y/n): “);
String firstAnswer = inputFromtheUser.readLine();
// —————————————————————-
// firstAnswer is NOT equal to “yes” and NOT equal to “y”,
// so we exit the program.
// —————————————————————-
if( ! firstAnswer.equalsIgnoreCase(“yes”) &&
! firstAnswer.equalsIgnoreCase(“y”))
break;
}while(true);
Source: i cannot remember where i get these codes but im certain that i found it in google.com// the code is BinarySearch.java. Give credits to him/her when you use these codes. thx alot.