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

  • Home
  • SEARCH
  • 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 8448467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:26:09+00:00 2026-06-10T10:26:09+00:00

I have a clarification about some Java code: What’s the difference between these codes,

  • 0

I have a clarification about some Java code:

What’s the difference between these codes, that one can be compiled while the other cannot.

I’m not interested on “how to fix the error” because I’ve already solved it, but more on an explanation about the problem:

Working

public void  x(){
    HashMap<String , Integer> count= new HashMap<String, Integer>();
    Scanner scan= new Scanner("hdsh");

    String tmp;
    while((tmp=scan.next())!=null){
        if(count.containsKey(tmp)){
            count.put(tmp, 1);
        }
        else{
            count.put(tmp, count.get(tmp)+1);
        }
         tmp=scan.next();
    }

}

Not Working

public void  x(){
    HashMap<String , Integer> count= new HashMap<String, Integer>();
    Scanner scan= new Scanner("hdsh");

    while((String tmp=scan.next())!=null){
        if(count.containsKey(tmp)){
            count.put(tmp, 1);
        }
        else{
            count.put(tmp, count.get(tmp)+1);
        }
         tmp=scan.next();
    }

}

The errors of Eclipse are:

Multiple markers at this line:

  • String cannot be resolved to a variable
  • Syntax error on token “tmp”, delete this token
  • String cannot be resolved to a variable
  • Syntax error on token “tmp”, delete this token
  • 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-10T10:26:10+00:00Added an answer on June 10, 2026 at 10:26 am

    JLS §14.12:

    WhileStatement:
        while ( Expression ) Statement
    

    JLS §15.27

    Expression:
        AssignmentExpression
    

    JLS §15.26

    AssignmentExpression:
        ConditionalExpression
        Assignment
    
    Assignment:
        LeftHandSide AssignmentOperator AssignmentExpression
    
    LeftHandSide:
        ExpressionName
        FieldAccess
        ArrayAccess
    

    LeftHandSide cannot be a declaration, so it is not allowed.

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

Sidebar

Related Questions

I just have one simple question about XSS attack. I know that you can
I just have a small question that I would like some clarification about, if
Just need some quick clarification I have 2 Queries in my Access Database that
I need some clarification. I have a Reportwriter dll that uses Crystal Reports. It
I have a page where a user can insert some order about some product.
i have some clarification regarding Qt programming. In Qt most of the time we
Suppose i have the code snippet as follows : ( clarification purpose/not well formed
I'm in need of some clarification. I've been reading about REST, and building RESTful
I need some clarification about the behaviour of svn switch. I'm using SVN version
I have a question about the values returned by getPosition. Below is my code.

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.