Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4608388
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:50:17+00:00 2026-05-22T00:50:17+00:00

I have just taken java programming course in college. And we were asked to

  • 0

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.

        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 < 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 < subjectTaken.length; j++) {
                    for (int k = 0; k < 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 && opt1) {
            summary(name1, name2, ID, GPA, totalGPA, semtaken, semcode);

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:50:18+00:00Added an answer on May 22, 2026 at 12:50 am

    You can’t allocate it but you can introduce it.

    int[] list = null;
    if (...) {
        list = new int[10];
    }
    Do what so ever with list.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, first, I'm a noob at android programming. I have taken some Java, but
So I have taken over a Java Web project . The application was written
I'm new to programming and have taken some classes in it so I'm not
I'm just transitioning from .NET to JAVA and have to start JAVA project with
I have just inherited a server application, however it seems that the only copy
I have just started learning Objective-C, I am reading Programming in Objective-C 3rd Edition
I have a Java application that I've been working on and I just realized
Just a small problem. Currently coding a Java project for a Dell Axim X51
I'm fairly new to programming in general but have been working with Java for
Here is some code from a lock-free queue using compareAndSet (in Java): public void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.