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 9046773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:44:03+00:00 2026-06-16T11:44:03+00:00

I am totally new to Java and I’ve started with some simple console applications.

  • 0

I am totally new to Java and I’ve started with some simple console applications.

This is my current application’s code:

Scanner sc = new Scanner(System.in);
boolean ExitLoop = false;
ArrayList<Integer> IDs = new ArrayList<Integer>();
ArrayList<Double> averages = new ArrayList<Double>();
while(!ExitLoop)
{
    System.out.println("StudentID: ");
    IDs.add(sc.nextInt());
    System.out.println("Average: ");
    averages.add(sc.nextDouble());
    System.out.println("Do you want to register another student? [y/n] ");
    ExitLoop = (sc.next() == "n");
}

Sorry to ask such a silly question but I am really stuck in this, I hit “n” but the while loop does not stop, and keeps working. Have I done anything wrong? what should I do to finish the loop when user enters “n” meaning no?

  • 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-06-16T11:44:05+00:00Added an answer on June 16, 2026 at 11:44 am

    One issue is:

    sc.next() == "n"
    

    should be

    sc.next().equals("n")
    

    String comparison should use equals() instead of == (except String literal comparison) and it is always better to follow java code conventions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I´m totally new to programming in java, and following some basic tutorials for my
I am totally new to everything in Java and it gets confusing some times,
I'm a student with quite some experience in Java but totally new to Maven.
hi i am a totally new guy on JAVA OO concepts ,and this is
I am totally new to Netty and Java, but this afternoon I have managed
I am totally new to Java Mail. I first wanted to execute the program
I'm new in the Java world and I'm totally confused with the sheer number
Totally new to programming so kindly excuse the silly question. I have this URL
im totally new when it comes to trying to make HTML code. I was
I'm totally new to this WCF Services thing so any guidelines would be greatly

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.