Computer Science, asked by arsh85601, 27 days ago

Write a Java program that prompts the user to enter any even integer value from the range 2 to 50 and find the index of entered value from an array that contains even numbers from 2 to 50

Answers

Answered by kamalrajatjoshi94
1

Answer:

Program:-

import java.util.*;

public class Main

{

public static void main(String args[])

{

Scanner in=new Scanner(System.in);

int n=2,ns,index=0;

int a[]=new int[25];

for(int i=0;i<25;i++)

{

a[i]=n;

n=n+2;

}

System.out.println("Enter the number to be searched which you want to display the index");

ns=in.nextInt();

if(ns>1&&ns<=50&&ns%2==0)

{

for(int i=0;i<25;i++)

{

if(a[i]==ns)

index=i;

}

System.out.println("The index of the number="+index);

}

else

System.out.println("Wrong Input");

}

}

The attachments are the outputs

  • The first photo displays the index of 6
  • The second photo displays the index of 10
  • The third photo is the output for an odd number
Attachments:
Similar questions
Math, 8 months ago