Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package class170629;
- import java.util.Scanner;
- public class arrays01 {
- public static void main(String[] args) {
- /*
- * Exercise 1, slide 28
- * input : 10 integer numbers to an array
- * output: even numbers only
- */
- // the size of the array
- final int SIZE = 10;
- // create a scanner
- Scanner s = new Scanner(System.in);
- // define an integer array
- int[] numbers = new int[SIZE];
- System.out.printf("Enter %d integer numbers:\n", numbers.length);
- // get data from user and save it in the array
- for (int i = 0; i < numbers.length; i += 1) {
- numbers[i] = s.nextInt();
- }
- s.close();
- // check numbers and print event numbers only
- for (int i = 0; i < numbers.length; i += 1) {
- if (numbers[i] % 2 == 0)
- System.out.printf("%d ", numbers[i]);
- }
- System.out.println();
- }
- }
Add Comment
Please, Sign In to add comment