Skip to content

Instantly share code, notes, and snippets.

@viveknarang
Created February 25, 2018 05:16
Show Gist options
  • Save viveknarang/cce3be68fcd36ef66d0a84b79282f99e to your computer and use it in GitHub Desktop.
Save viveknarang/cce3be68fcd36ef66d0a84b79282f99e to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class FindMatchValue {
public static void main (String [] args) {
final int NUM_VALS = 4;
int[] userValues = new int[NUM_VALS];
int i;
int matchValue;
int numMatches = -99; // Assign numMatches with 0 before your for loop
userValues[0] = 2;
userValues[1] = 2;
userValues[2] = 1;
userValues[3] = 2;
matchValue = 2;
numMatches = 0;
/* Your solution goes here */
for (i = 0 ; i < NUM_VALS; i++) {
if (userValues[i] == matchValue) {
numMatches++;
}
}
System.out.println("matchValue: " + matchValue + ", numMatches: " + numMatches);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment