• Post Reply Bookmark Topic Watch Topic
  • New Topic

Eclipse doesn't show println() in console  RSS feed

 
Andrey Shestakov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I'm just start learning java and met the following problem:

in my program I have only one method main (String[] args) and when I make another part of program in {}, it doesn't show the result in console

Unfortunately, I can't paste it here, just attached screenshot of Eclipse Workspace.

Please, help me to solve this problem.
Thank you.
Untitled.png
[Thumbnail for Untitled.png]
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrey Programmer wrote:
in my program I have only one method main (String[] args) and when I make another part of program in {}, it doesn't show the result in console


Please explain what what you mean by the part in bold. I can only guess from the screen shot that you made it as part of an instance initializer. Can you confirm this?

And if so, can you show use the code that does the instantiation of the Program class?

Henry
 
Andrey Shestakov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, refer to the attached file for the text of program.

Eclipse don't show result of out.println(r);

out.printf("a = %d\nb = %d\n", a, b);

out.printf ("d=%f", d);

out.printf("%1$tY-%1$tB - %1tD", now);

Unfortunately, I can't attach niether .jar niether .txt file.

If it is possible, I can forward it to e-mail or using skype.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrey Shestakov wrote:Unfortunately, I can't attach niether .jar niether .txt file.

You don't need to. you should post the relevant part of the program in your replies being sure to UseCodeTags (⇐ that's a link).

If it is possible, I can forward it to e-mail or using skype.

Again, you should post any relevant information in the replies. Offline communications is frowned upon.
 
Andrey Shestakov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyway, you are right.

I'm just using one method main public static void main(String[] args) as instance initializer.
 
Andrey Shestakov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the full code:

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrey Shestakov wrote:
I'm just using one method main public static void main(String[] args) as instance initializer.


No. You have one main() method, and three instance initializers. And since you don't actually create any instances of Program, the instance initializers will not be executed.

Henry
 
Andrey Shestakov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry, instance=object, am I right?

Can I reate initializer of instance in such way:

public static void A(), for example? Using method "A".

 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create methods. But you need to actually call those methods to see any result.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Agreed. Now you have four static methods -- main(), A(), B(), and C(). The JVM will call main() -- your code (meaning the code in main()) must call the others.

Henry
 
Andrey Shestakov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, should I see the result in the code above for these four methods?

Now no any mistakes but anyway I don't see results except discribed using method main ().
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrey Shestakov wrote:So, should I see the result in the code above for these four methods?

Now no any mistakes but anyway I don't see results except discribed using method main ().


Correct. You should only see the output for the main() method... as there isn't any code in your program that calls the other three methods.

Henry
 
Andrey Shestakov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I called them with such code in main():

Program.A();

Program.B();

Program.C();

Is it correct? Is there another common way to do it?
Thank you.
 
Carey Brown
Saloon Keeper
Posts: 3314
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That should work but because all of this happens inside of your Program class the use of "Program." is unnecessary. You can just call "A();".
 
Andrey Shestakov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your kind help!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!