• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

How do I make the last few lines of the code into a method?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Rancher
Posts: 4893
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please edit your post and wrap the code in code tags: Select the code and press the Code button.
 
Scott Baban
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Please edit your post and wrap the code in code tags: Select the code and press the Code button.


Sorry I'm new here and the mobile version of this site doesn't have sufficient options. But I made changes already. Thanks
 
Norm Radder
Rancher
Posts: 4893
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some how the code has lost all its indentations making it harder to read and understand.

A method is declared outside of another method.    See the tutorial:  https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html

Add the lines to it that you want and declare its arguments as needed.
 
Scott Baban
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Some how the code has lost all its indentations making it harder to read and understand.

A method is declared outside of another method.    See the tutorial:  https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html

Add the lines to it that you want and declare its arguments as needed.



I'm new to Java and still learning stuff. I'm having problems understanding methods and arrays, I'm learning more in the Internet than in my classes. But I'm trying to read more and watch vids on Java.

Btw these lines are the ones I wanted to convert into a method.
 
Scott Baban
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Some how the code has lost all its indentations making it harder to read and understand.

A method is declared outside of another method.    See the tutorial:  https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html

Add the lines to it that you want and declare its arguments as needed.



And also I tried making one but I failed to do so, it had many errors...

I'm having problems understanding and making methods. Your help is much appreciated.


 
Norm Radder
Rancher
Posts: 4893
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it had many errors..


If you need help with the errors, copy the full text of the error messages and paste it here.

Note: Java has a class named Array.  Its better to have your own unique name and not use one defined in the java classes.
 
Scott Baban
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:

it had many errors..


If you need help with the errors, copy the full text of the error messages and paste it here.

Note: Java has a class named Array.  Its better to have your own unique name and not use one defined in the java classes.



It has errors on the namelength and the scanner and other symbols not recognized.
 
Norm Radder
Rancher
Posts: 4893
38
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It has errors on ...


Please copy the full text of the compiler's error messages and paste it here. It has important info about the errors.  The exact text please.

Also the code's indentations need to be fixed.  Several statements are not properly indented making the code harder to read and understand.
 
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See HowToFormatCode (that's a link).
 
Ruth Stout was famous for gardening naked. Just like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic