Why Is My Java Program Not Working?

Click For Summary
SUMMARY

The discussion centers on troubleshooting a Java program where the user encounters issues with the Scanner class. The primary mistakes identified include the incorrect method names 'nextint()' and 'nextdouble()', which should be 'nextInt()' and 'nextDouble()' respectively, adhering to Java's naming conventions. Additionally, it is recommended to use lowercase for object names, such as 'sc' instead of 'Sc', and to utilize 'System.out.print(...)' for input prompts instead of 'System.out.println(...)' for better aesthetics.

PREREQUISITES
  • Understanding of Java programming language
  • Familiarity with the Scanner class in Java
  • Knowledge of Java naming conventions
  • Basic debugging skills in Java
NEXT STEPS
  • Review Java documentation on the Scanner class methods
  • Learn about Java naming conventions for variables and methods
  • Explore best practices for input/output in Java
  • Practice debugging Java programs using an IDE like BlueJ
USEFUL FOR

Java developers, students learning programming, and anyone looking to improve their coding practices and debugging skills in Java.

grzz
Messages
1,030
Reaction score
26
TL;DR
I need help because I cannot find mistakes in my java program.
Please help me to find what my mistakes are in the following java program.
 

Attachments

Technology news on Phys.org
From the next time onwards, please post your code inside the code tags instead of a screenshot. That helps us to directly quote portions of the code rather than typing out everything again. Click on this:

1672309365723.png


paste your code, select the language and click on Continue.

That aside, from your screenshot, I see BlueJ already highlights the errors. There is no function nextint() or nextdouble() in the Scanner class. It's nextInt() and nextDouble(). Note the capitals. These follow from the Java function naming conventions.

Also, it is better if you name objects using the naming conventions. sc (small letters) is better than Sc. In addition, when you are taking input, you can use System.out.print(...) instead of System.out.println(...). The last one is just for aesthetics, though.
 
  • Like
Likes   Reactions: FactChecker, jim mcnamara and pbuk
grzz said:
TL;DR Summary: I need help because I cannot find mistakes in my java program.

Please help me to find what my mistakes are in the following java program.
Please repost your thread using the instructions from @Wrichik Basu -- You really need to post the code within code tags if you want to get help at PF with your code. Please also tell us what you think is wrong with the code; are you getting errors?

This thread is closed.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 14 ·
Replies
14
Views
1K
Replies
86
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K