Valeri12580

Learning Methods

Jan 6th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Exercise4 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. System.out.print("Enter number:");
  7. int n = Integer.parseInt(scanner.nextLine());
  8. System.out.print("Enter array's length:");
  9. int numArray = Integer.parseInt(scanner.nextLine());
  10. checkNumber(gettingArray(numArray),n);
  11. }
  12.  
  13. public static int[] gettingArray(int numArray) {
  14. Scanner scanner = new Scanner(System.in);
  15. int[] array = new int[numArray];
  16.  
  17. for (int i = 0; i < numArray; i++) {
  18. int numberInArray = Integer.parseInt(scanner.nextLine());
  19. array[i] = numberInArray;
  20. }
  21. return array;
  22. }
  23.  
  24. public static void checkNumber(int[] array,int tursenoChislo) {
  25. int counter = 0;
  26.  
  27. for (int i = 0; i < array.length; i++) {
  28. if (tursenoChislo== array[i]) {
  29. counter++;
  30.  
  31. }
  32.  
  33. }
  34. System.out.printf("The array contain the number (%d) %d times",tursenoChislo, counter);
  35. }
  36. }
Add Comment
Please, Sign In to add comment