public static void main(String[] args) { int[] array = {100,22,3,44,55,66,77,88}; Scanner scanner = new Scanner(System.in); System.out.println("Enter number that you are looking for:"); int number = scanner.nextInt(); //int search; for(int i=0; i<array.length; i++) { if(number == array[i]) { System.out.printf("number %d is in the array it's index %d \n", number, i); } else { System.out.println("sorry"); } } scanner.close(); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter