• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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: 13280
292
  • 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: 74042
332
  • 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: 24314
167
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"?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic