Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package class170629;
- import java.util.Scanner;
- public class arrays07 {
- public static void main(String[] args) {
- /*
- * Exercise 7, slide 29
- * input : 10 numbers , save every 5 to an array
- * output: the same keys that has the same values
- */
- // size of each array
- final int SIZE = 5;
- // create a scanner
- Scanner s = new Scanner(System.in);
- // define an integer arrays
- int[] numbers1 = new int[SIZE];
- int[] numbers2 = new int[SIZE];
- System.out.printf("Enter %d integer numbers to first array:\n",
- numbers1.length);
- // get data from user and save it in the array
- for (int i = 0; i < numbers1.length; i += 1) {
- numbers1[i] = s.nextInt();
- }
- System.out.printf("Enter %d integer numbers to seconed array:\n",
- numbers2.length);
- // get data from user and save it in the array
- for (int i = 0; i < numbers2.length; i += 1) {
- numbers2[i] = s.nextInt();
- }
- s.close();
- // check numbers at the same position, if equal then print the position
- for (int i = 0; i < numbers1.length; i += 1) {
- if (numbers1[i] == numbers2[i])
- System.out.printf("%d is in place %d in both arrays\n", numbers1[i], i);
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement