• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with the Scanner (system in) ability

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey, I recently made a program in Eclipse involving "scanner". it allowd the user to plug in 2 numbers-and java would spit back certain text as well as the adding the 2 numbers and giving the sum.

works fine-however,the same exact response now occurs on every program I make or have already made (whether or not its in the same package/src folder)

why is this happeing (would like to know for education purposes if that's alright) and how can I can I relegate the scanner program to its own page?

("scanner program")




when i run- the console says "type in any 2 numbers" (not exact wording)-and the same thing appears on all my other programs


(this is an example of my program)

Type in 2 numbers you wish to add

//im going to write out an example now-with the java program underlined and the users input in regular


1
+
2
The sum:=3

4.2
5.1
the decimal answer is 9.3
 
Ranch Hand
Posts: 55
jQuery Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does other programs have main method?
How are you running it?Ctrl+F11??
 
Ranch Hand
Posts: 449
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Welcome to javaranch

To be honest, I think i didn't get your question. What do you mean by how can I can I relegate the scanner program to its own page?

Also, the program output also seems correct. I am sorry but I didn't able to get this sentense "type in any 2 numbers" (not exact wording)-and the same thing appears on all my other programs "
 
Muhammad Khojaye
Ranch Hand
Posts: 449
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I got your problem now . Click "Run As -> Run Configuration" and check the main class. It might be the old one always.
 
Samuel Weston
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh wow! that was it! ^^
thank you so much muhammed
and also wanted to say thanks to all those on this post- I was very surprised that not only did you guys try to give an answer-you were very considerate while doing so (most forums I have been on consisted of bullies)

post question:
what exactly is the "run configurations"? and how would I change it so that the one program (the one I titled "InputOutput) dsnt cross over to other programs?
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome again

I have added code tags to your post and removed the excess blank lines. That usually makes it look a lot better, but your indentation is inconsistent. Try ctrl‑A‑ctrl‑I in Eclipse.
I don't understand what you mean about crossing over; are you using the Run Last button on Eclipse? That calls the last thing you executed and runs it again. If I use Eclipse, I usually right‑click the class with main method and run as→Java application (or similar). That way you can invoke the main method on any class.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried to sort out the indentation, with a little success. Please don't mix tab and spaces: look at this suggestion. You can set options in Eclipse to use 4 spaces at a time automatically.
I also had to insert line 6 which appeared to have been omitted.
You may find that entering 8.1 and 3.1 fails to get the “cool” response. Maybe, maybe not. That is because of, well look here (No. 20). Actually I haven't managed to get it to fail yet.
 
Samuel Weston
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome again

I have added code tags to your post and removed the excess blank lines. That usually makes it look a lot better, but your indentation is inconsistent. Try ctrl‑A‑ctrl‑I in Eclipse.
I don't understand what you mean about crossing over; are you using the Run Last button on Eclipse? That calls the last thing you executed and runs it again. If I use Eclipse, I usually right‑click the class with main method and run as→Java application (or similar). That way you can invoke the main method on any class.




ok thank you for the info.

the "crossing over" I keep mentioning is when clicking on "Run As -> Run Configuration" -if the main class is the same as for example my program "InputOutput" then any other program I try to run will
have the same printout as "InputOutput"

my question is actually a more simple one. how and why does the main class affect a program?
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is 2am here, so my brain is not working at 100% efficiency, but …

Stop using Eclipse. IDEs are really good for experienced people, but they introduce an additional learning curve and brain‑load when your brain is already heavy laden with Java.
Write the following instructions at a command prompt/terminal window, and after the second edit the .java file and save it in the new directory. You don't have to call the directory java; any sensible name will do

mkdir java
cd java
javac usingBothInputOutput.java
java usingBothInputOutput

Note you use the .java extension first time and omit it second time.

Like many people here, I believe it is best to get accustomed to the command line before using an IDE.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic