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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:04:34+00:00 2026-05-27T23:04:34+00:00

Newbie question, but I have this code: import java.util.*; import java.io.*; public class Welcome1

  • 0

Newbie question, but I have this code:

import java.util.*;
import java.io.*;

public class Welcome1  
{
   // main method begins execution of Java application
   public static void main( String[] args )
   {
      String confirm = "y";
      while(confirm=="y")
      {
         System.out.println( "Welcome to Java Programming!" );
         System.out.println( "Print Again? (y/n)" );
         Scanner input = new Scanner(System.in);
         confirm = input.nextLine();
      }
   }
}

I just need to simply print the welcome message again when user input “y” when asked.
But it’s not working. Any ideas?

  • 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-27T23:04:35+00:00Added an answer on May 27, 2026 at 11:04 pm

    In Java, the primitive types (int, long, boolean, etc.) are compared for equality using ==, whereas the Object types (String, etc.) are compared for equality using the equals() method. If you compare two Objects types using ==, you’re checking for identity, not equality – that is, you’d be verifying if the two objects share exactly the same reference in memory (and hence are the same object); and in general, what you need is just verifying if their values are the same, and for that you use equals().

    As a good programming practice, it’s better to compare Strings like this, flipping the order of the strings:

    while ("y".equals(confirm)) {
    

    In this way, you can be sure that the comparison will work, even if confirm was null, avoiding a potential NullPointerException.

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

Sidebar

Related Questions

This is sort of SQL newbie question, I think, but here goes. I have
Ok so this is a newbie question on java, but i can't seem to
I'm newbie in Python, but this question is not a homework (actually this code
I think that this is a newbie type question but I have quite understood
Total newbie question but this is driving me mad! I'm trying this: myInt =
this is a bit of a newbie question but hoping I can get some
I'm sure this is a newbie question, but every time I've compiled/dl'ed a new
I know this is a total newbie question, but the answer may not be
This might be a very newbie question, but I didn't find anything satisfying I
I realize this is probably a hopelessly newbie question, but what is the difference

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.