Consider the program segment below. If the user inputs 1004, to which array index is the input being compared with?
View the step-by-step solution to:

Question

Consider the program segment below. If the user inputs 1004, to which array index is the input being compared

with?

Scanner sc=new Scanner(System.in);

System.out.print("Enter the student ID --> ");

int input=sc.nextInt( );

int[] id={1001,1002,1003,1004,1005};

for(inti=0;i<id.length;i++){

if(input==id[i]){

System.out.println("ID   : "+ id[i]);

    }           

}

Top Answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question