Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Run more than one code?  RSS feed

 
Chase Harris
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have a question I'm trying to solve. I am supposed to display four patterns using loops. I have the coding for each pattern, but is there a way to have them all in the same .java file? Here's my code:


When I run, I can only do the output for the first pattern. I just don't know how to go about combining them. Is there a way to do all of them without separating each into their own file/project? Thanks.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37222
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only have one main method. However, that method can call other methods.
 
Chase Harris
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:You can only have one main method. However, that method can call other methods.
Do you have an example? My book doesn't talk about this.
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chase Harris wrote:Do you have an example? My book doesn't talk about this.


Did you get to the section regarding creating methods yet? If not, here is the section from the Oracle tutorial... https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html

Henry
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why have you marked everything static? Using the keyword static without a good explanation is a mistake. “Because it wouldn't compile otherwise,” is not a good explanation.
 
T Tak
Greenhorn
Posts: 7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be this is what you are looking for


 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this, which is on the contents page of this forum:-
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
By providing a complete solution you are depriving the OP of the opportunity to learn from this experience; also if this is assessed work there is a risk OP will be accused of plagiarism and get a mark of 0.
Please don't get annoyed, but I have pulled rank and deleted the solution, except one part which regular readers will doubtless see in a few seconds will fail to “work”.
 
T Tak
Greenhorn
Posts: 7
Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got the point.. is useful for future posts
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!