Intro to Tutorial Challenges
The following is the solution to hacker rank problem "Intro to Tutorial Challenges" using Java. Visit my page hackerrank for solutions to other Hacker Rank problems.
Score: 2/2
| 
/** 
 *  
 */ 
package hackerRank; 
import java.util.Scanner; 
/** 
 * @author Arun.G 
 *  
 */ 
public class
  IntroToTutorialChallenges { 
       /** 
        * @param args 
        */ 
       public static int findValueInArray(int[] ar, int value) { 
              for (int i = 0; i < ar.length; i++) { 
                     if (ar[i] == value) 
                           return i; 
              } 
              return -1; 
       } 
       public static void main(String[]
  args) { 
              // TODO Auto-generated
  method stub 
              Scanner sc = new Scanner(System.in); 
              int value =
  sc.nextInt(); 
              int n = sc.nextInt(); 
              int[] ar = new int[n]; 
              for (int i = 0; i < n;
  i++) { 
                     ar[i] = sc.nextInt(); 
              } 
              System.out.println(findValueInArray(ar,
  value)); 
       } 
} | 
 
No comments:
Post a Comment