Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /* ==================================================
- Chapter 2: Syntax section C- Arrays
- Ex7: Display indexes where identical values
- ===================================================
- */
- public class MyProgram {
- public static void main(String[] args) {
- //variables
- final int SIZE=5;
- int arr1[]=new int[SIZE];
- int arr2[]=new int[SIZE];
- Scanner s=new Scanner(System.in);
- //init array 1
- System.out.println("Enter 5 values for array1: ");
- for(int i=0;i<arr1.length;i++){
- arr1[i]=s.nextInt();
- }
- //init array 2
- System.out.println("Enter 5 values for array2: ");
- for(int i=0;i<arr2.length;i++){
- arr2[i]=s.nextInt();
- //print index if identical values
- if (arr1[i]==arr2[i])
- System.out.println("index: "+i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment