Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Netbeans util.Scanner wont run

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
New at this first week of class. Why wont this run? Im using netbeans12.4
Capture.PNG
[Thumbnail for Capture.PNG]
 
Saloon Keeper
Posts: 13422
300
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

The print() method doesn't immediately write its output to the underlying stream. Instead, it buffers (memorizes) the data until you write a newline character or you call flush().

It appears you want the user input to appear on the same line as the question you're asking the user. That means you have to call System.out.flush() before you use System.in.

In the future, when you ask a question about some code, please copy and paste the code as text, and put "code tags" around it like [code]this[/code]. Don't post screenshots of code, they make it hard for us to help you.
 
Matthew Love
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You Stephan
 
Marshal
Posts: 74390
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you running that code? Where is the console on NetBeans? Surely at the bottom right. The messages there make me suspect you aren't giving NetBeans the correct instructions to run that code.

And, again, welcome to the Ranch
 
Saloon Keeper
Posts: 24587
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch! Now if you can just learn the difference between NetBeans and Java.

This wasn't a Netbeans problem, by the way.

As others pointed out, to get your prompt message to display you need to flush System.out. For cases where you want to print a complete line and not wait for input to be typed on the same line you can use System.out.println(), which does a flush() automatically.

And yes, we really do prefer that you paste actual text and not screenshots. It's easier for us to read and doesn't consume as much server resources.

Oh, also, did you realize you mis-spelled  "integer"?
 
reply
    Bookmark Topic Watch Topic
  • New Topic