plz answer 1 Answer(s) 3 years and 2 months ago
Posted in : Java Beginners
Write a Binary Search program that searches an array of ordered data. Compose an ordered array of 500 integers that contains the following series of numbers and run the search on it: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
View Answers
March 15, 2010 at 2:51 PM
Hi Friend,
Try the following code:
import java.util.*; class BinarySearchExample{ public static void main(String[] args){ int counter=0; int[] intArray = new int[40]; int searchValue = 0, index; int f1, f2 = 0, f3 = 1; for (int i = 0; i < intArray.length; i++) { f1 = f2; f2 = f3; f3 = f1 + f2; intArray[i]=f3; System.out.println(intArray[i]); } System.out.print("Enter a number to search for: "); Scanner input=new Scanner(System.in); searchValue = input.nextInt(); index = binarySearch(intArray, searchValue); if (index != -1) { System.out.println("Found at index: " + index); } else { System.out.println("Not Found"); } } static int binarySearch(int[] search, int find) { int start, end, midPt; start = 0; end = search.length - 1; while (start <= end) { midPt = (start + end) / 2; if (search[midPt] == find) { return midPt; } else if (search[midPt] < find) { start = midPt + 1; } else { end = midPt - 1; } } return -1; } }
Thanks
Related Pages:
plz give me answer plz plz give me answer plz writw a programme to find rank from an array using doubledimmensionalarray
plz give me answer plz give me answer description about string class methods
Java string methods
plz give me answer plz give me answer description about string class methods
Java string methods
plz give me answer plz give me answer description about string class methods
Java string methods
plz give me answer plz give me answer Discuss & Give brief description about string class methods
Java string methods
Plz answer - Java Beginners Plz answer Create a Java Bean Class â?? Customer according to the below given class diagram.
Customer...
-------------------------------------------------
plz doreply me....thankz alot
 
plz answer - Java Beginners plz answer Write a Binary Search program that searches an array of ordered data. Compose an ordered array of 500 integers that contains the following series of numbers and run the search on it:
1, 2, 3, 5, 8, 13, 21, 34, 55
Plz send me answer quckly Plz send me answer quckly Respected Sir,
myself is pavan shrivastava.i want ask a question that is ( we can't
create object of interface then how would possible to create object
plz. answer my ques - Java Beginners plz. answer my ques I want to ask a prog. prob which would create a prog that would simply take username and password as input and will display ***** while taking passwords as input.(As it is done at login in websites).
Also
need the answer vry urgently..plz help me...[plzzzzzzzz
need the answer vry urgently..plz help me...[plzzzzzzzz the question... code...hpw to write in eclipse platform....plzplz mail me...to panda.pragnya7@gmail.com/panda_pragnya@yahoo.com...plzplz...help....me..it can change my lyfe
ArrayList question plz solve it
ArrayList question plz solve it An arraylist object stores an Emp Object, where there is name,age,address of the employee is stored,
And i want to access the data in the basis of age based?
Provide answer to the question
help plz - Java Interview Questions
/ output the number of milk cartons needed to hold milk (round your answer... , if the input string is abcd, the output is : edcba
plzplzplzplzplz help
help plz - Java Interview Questions
help plz 1 )write a program that does the following :
a. prompts the user to input five decimal numbers representing the scores?
b. prints.../ output the number of milk cartons needed to hold milk (round your answer
OCI Connectivity For Oracle Plz Solve This Error
OCI Connectivity For Oracle Plz Solve This Error import java.io....)
{
e.printStackTrace();
}
}
}
---> I found Error below how i can solve this error plz tell me some answer
Package not found Error
OCI Connectivity For Oracle Plz Solve This Error
OCI Connectivity For Oracle Plz Solve This Error import java.io....)
{
e.printStackTrace();
}
}
}
---> I found Error below how i can solve this error plz tell me some answer
Package not found Error
Can u Look to the error plz - Java Beginners
;where is the answer sir.?
just i want from you to look what is the error plz...Can u Look to the error plz this is my code can u modify it plz and give me the result of it when u check it on eclipse or jcreator plz and i
answer it soon answer it soon write a proggram to accept a number and check whether the sum of prime factors of a number is a prime number
java, plz help me in doing this - Java Beginners
java, plz help me in doing this # Write a small record management application for a school. Tasks will be Add Record, Edit Record, Delete Record...();
}
}
Hope that it will be helpful for you.
Thanks The answer above
java.please answer this...
java.please answer this... Q1).How we can write a complete JAVA program that computes the following summation formulas..?
â??_(i=1)^nâ??ã??i^2=ã?? (n^(2 ) ã??(n+1)ã??^2)/4
plz help plz help what is the procedure and code to design an interactive GUI in java using swings
Plz Help Plz Help Hello Guys!! Plz. Help
I need to write a program to display the astrological sign based on your birthday for example
If we enter the date of birth in the following format from console--13/08/1990
it should give you
plz plz rply as soon as possible plzplz rply as soon as possible by using c programs
* * *
* * s s s s s
* s s o s s
s s s s s
s s s s s
s s
s s
s s
s s s s s
Answer for SCJP Module-1 Question-13 Answer for SCJP Module-1 Question-13 The Answer for SCJP Module-1 Question-13 is missing , I think the answer is option '1', Correct me if I am wrong
pls answer the Trangle pattern
pls answer the Trangle pattern a b c d e
b c d e
c d e
d e
e
Please answer and give the code for above triangle
Urgent Answer Req
Urgent Answer Req how to view the file content which is at client side from jsp in java
Constructor Chaining Answer
Java NotesConstructor Chaining Answer
Answers to the question in
Constructor Chaining.
Grandparent() constructor
Parent(25) constructor
Parent() constructor
Child() constructor
Copyleft 2003 Fred Swartz
MIT License,
Last
please answer me
please answer me iam using html in select tag.in this one option i selected and that option data will be display in table.And use servlet with html and how to retrieve the data from data base
Please give me the answer.
"int a=08 or 09" its giving compile time error why "int a=08 or 09" its giving compile time error why ?
can any one give me the answer of this please
share your answer to this question
share your answer to this question i need to know what is the TELERIK CONTROL?
what is the map suite?
what is dunda chart?
Also i have to know what are the websites available which give infor regarding this.
Let me know how
pls answer these question
pls answer these question Write a program that prompts the user to input the length and width of a rectangle.
Then calculate and prints the rectangleâ??s area and perimeter.
import java.io.*;
class rectangle
Is the answer 35, 35?
Is the answer 35, 35? int a = 5;
int b = 7;
int num = 35;
while (a < b)
{
System.out.println(?My age is ? + num);
a = a + 1;
}
Hello Friend,
class Check{
public static void main(String[] args
answer me this program answer me this program Java Code to Maintain student record,Name, Age, Marks of 5 subjects for a Student,Display Student age and name,Calculate Average of all marks and display it
Java student record
import
answer me this program answer me this program Java Code to Maintain student record,Name, Age, Marks of 5 subjects for a Student,Display Student age and name,Calculate Average of all marks and display it
Java student record
import
Plz Plz reply Me - JSP-Servlet PlzPlz reply Me Respected Sir/madam,
I am R.Ragavendran.. Actually I got your coding.. But This code is not enabling the user to click and change the image..
I request you to remember the code which you have provided for me
please send me the answer - JDBC
please send me the answer -difference between DriverManager and DataDourse what is Datasourse? What r the advantages? what is the difference between DriverManager and DataDourse
plz help me today plz plz - Java Interview Questions plz help me today plz plz 2.) Suppose list is an array of six elements of type int. What is stored in list after the following java code executes?
.
for (i = 0; i < 5; i++)
{
list[i] = 2 * i + 5