jwrbg

FindElementIndex

Feb 20th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. public class FindElementIndex
  7. {
  8. public static void main(String[] args)
  9. {
  10. Scanner scanner = new Scanner(System.in);
  11. System.out.println("Vyvedi chislo");
  12. int inputNum = scanner.nextInt();
  13. int[] arr = {5, 7, 3};
  14.  
  15. while (true) {
  16. int printed = -1;
  17. for (int i = 0; i < arr.length; i++) {
  18. if (arr[i] == inputNum) {
  19. printed = i;
  20. break;
  21. }
  22. }
  23. System.out.println(printed);
  24. System.out.println("Vyvedi chislo");
  25. inputNum = scanner.nextInt();
  26. }
  27. }
  28. }
Add Comment
Please, Sign In to add comment