• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Run more than one code?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 42135
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 80624
470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 7
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be this is what you are looking for


 
Campbell Ritchie
Marshal
Posts: 80624
470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
got the point.. is useful for future posts
 
Campbell Ritchie
Marshal
Posts: 80624
470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic