โปรแกรมหาเลขคู่-คี่ | ในบรรทัดที่ 16-24

ในบรรทัดที่ 21-23 เมื่อผมพิมพ์ตัวอักษรลงไปมันจะทำการแจ้งเตือนว่า "Error : Don't input by charactor"
สิ่งที่ผมต้องการคือ เมื่อแจ้งเตือนแล้ว อยากให้กลับไปทำ ในบรรทัดที่ 17-19 ใหม่
ผมลองทำหลายลูปแล้วครับ ผมทำไม่ได้ ถ้ามีใครทำได้ก็ช่วยบอกทีนะครับ
ขอบคุณครับ


อันนี้โค้ดครับ :
package test08_3;

import java.util.*;

public class test08_3 {
    
    public static void main(String[] args) {
        Scanner scan;
        ArrayList<Integer> arr;
        int n, i = 0;
        scan = new Scanner(System.in);
        arr = new ArrayList<Integer> ();
        
        System.out.print("Enter number : ");
        n = scan.nextInt();
        try {
            for(i = 0; i < n; i++) {
                arr.add(scan.nextInt());
            }
        }
        catch(InputMismatchException e) {
            System.err.println("Error : Don't input by charactor");
        }
        
        //#################################################################################
        
        int a, b = 0, c = 0, j;
        String str = "";
        for(j = 0; j < arr.size(); j++) {
            a = arr.get(j);
            if( a % 2 == 0)
            {
                str = " EVEN";
                b++;
            }
            else
            {
                str = " ODD";
                c++;
            }
            System.out.println("Index["+j+"] " + arr.get(j) + " is :" + str);
        }
        System.out.println("EVEN = " + b + " Unit |" + " ODD = " + c + " Unit");
    }
}
แก้ไขข้อความเมื่อ
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่