Using variables declared inside the IF statement
<p>I have just taken java programming course in college. And we were asked to do a project. However, I am facing a dilemma here and some assistance will be highly appreciated.    </p>

<pre><code>        if (opt == 1) {
            System.out.println("Enter your name:");
            name1 = keyboard.next();
            name2 = keyboard.next();
            System.out.println("Enter your ID:");
            ID = keyboard.nextInt();
            System.out.println("Enter semesters taken:");
            semtaken = keyboard.nextInt();
            int[] semcode = new int[semtaken];
            int[] subjectTaken = new int[semtaken];
            double[] GPA = new double[semtaken];
            double finalGPA;
            for (i = 0; i &lt; semtaken; i++) {
                System.out.println("Enter semester code for semester no " + (i + 1));
                semcode[i] = keyboard.nextInt();
                System.out.println("Enter subjects taken:");
                subjectTaken[i] = keyboard.nextInt();
                String[][] subject = new String[subjectTaken[i]][4];
                int subjectsTakenNO = subjectTaken[i];

                System.out.println("Enter your subject code, hours, letter");
                for (j = 0; j &lt; subjectTaken.length; j++) {
                    for (int k = 0; k &lt; 3; k++) {
                        subject[j][k] = keyboard.next();
                    }

                }

                GPA[i] = getGPA(subject, subjectsTakenNO);
                totalGPA += GPA[i];
                finalGPA = totalGPA / semtaken;
                System.out.println("Your GPA for this term is" + getGPA(subject, subjectsTakenNO));
            }
            opt1 = true;
        } /* Here is the PROBLEM. I want to get I want to get semtaken and gpa but it shows an
             error (Variable not found) */ 
        else if (opt == 2 &amp;&amp; opt1) {
            summary(name1, name2, ID, GPA, totalGPA, semtaken, semcode);
</code></pre>

<p>So basically, I want to use totalGPA,semtaken,semcode and GPA which are inside the IF. How can I use them without showing me an error "Variable not found"? I cant initialize the array before the IF  because I dont know its size. The user inputs the size so it has to be inside the IF. </p>
