
In Java please.
Add comments too!
thank you!
![Create a Java program with a method that searches an integer array for a specified integer value (see help with starting the method
header below). If the array contains the specified integer, the method should return its index in the array. If not, the method should
throw an Exception stating "Element not found in array" and end gracefully. Test the method in main with an array that you make
and with user input for the "needle".
public static int returnIndex(int[] haystack, int needle) {](https://content.bartleby.com/qna-images/question/a8d3ff56-1af2-434e-8740-80c67d4b592b/a85a4f47-9915-4e3b-80fc-fcb401951ad0/q1ptc4m_thumbnail.png)

code-
import java.util.Scanner;
public class Main
{ public static int returnindex(int[] haystack , int needle) {
if (haystack == null) {
return -1;
}
int len = haystack.length;
int i = 0;
while (i < len) {
if (haystack[i] == needle) {
return i;
}
else {
i = i + 1;
}
}
return -1;
}
public static void main(String[] args) {
int[] haystack = { 1,2,3,4,5,6 };
Scanner sc = new Scanner(System.in);
int needle = sc.nextInt();
if (returnindex(haystack,needle)>=0){
System.out.println(returnindex(haystack,needle));}
else{
throw new ArithmeticException("Element not found in array");
}
}
}
Step by stepSolved in 2 steps with 1 images

- Explain in your own words what inline comments are for and how they work.arrow_forwardUse ruby on rails Add the following parts to your student management system. Prefix: prefix, has many courses. Course: Belongs to a prefix, number, name, has many sections. Semester: semester ("Spring", "Summer", "Fall", …), year, has many sections. Section: CRN, belongs to a course, belongs to a semester. Clean up the browser display for the following. Foreign keys are not displayed, but reasonable text is. There is a drop-downs for prefixes when creating courses, and drop-downs for course and semester when creating a section. A course displays all the sections. A semester displays all the sections. Something reasonable is displayed if a null is detected.arrow_forwardIn your packages, why would you want to add javadoc comments?arrow_forward
- Before I email my PowerPoint to my professor, I'd appreciate it if you could double-check all of the citations and references it contains.arrow_forwardcreate a game space invaders using java.arrow_forwardWhat is a Java class? 2. How do you create a Java class? 3. How do you create instances of a class?arrow_forward
- Look at the book you are reading right now. Is it an object or a class? If it is a class, name some objects. If it is an object, name its class.arrow_forwardUse ruby on rails and on command line. Add the following parts to your student management system. Prefix: prefix, has many courses. Course: Belongs to a prefix, number, name, has many sections. Semester: semester ("Spring", "Summer", "Fall", …), year, has many sections. Section: CRN, belongs to a course, belongs to a semester. Clean up the browser display for the following. Foreign keys are not displayed, but reasonable text is. There is a drop-downs for prefixes when creating courses, and drop-downs for course and semester when creating a section. A course displays all the sections. A semester displays all the sections. Something reasonable is displayed if a null is detected.arrow_forwardPlease help me with this. Read what is asked carefully Yes or no does the java tic tac toe gui game on the website (java gui tic tac toe codespeedy) have a searching g algorithm or search java code. Please do not write the code unto Bartleby. I just need a yes or no answer and the why or why not in simple sentencesarrow_forward
- Find a way to increase the value of X by 10 while processing a game object in JavaScript?arrow_forwardCan you please answer the following question? The program is JavaScript and needs to look exactly like the example attached. Thanks!arrow_forwardCompare three IDEs for development using Java- The best interfaces- Easier to handle- Installation methodarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





