• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Beginner with problems in code

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator





I am getting errors in this code and i am quite honestly lost, i have been reading text and examples for a week and am just not understanding this.  Any help would be great.
 
Bartender
Posts: 10980
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code you posted is incomplete, can you post the whole thing? Can you also post the text of the error message that you're getting?
 
Joe Robinson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We were given this as a template to use and i have no idea where to go with this.  i have filled in a lot of the information and got it to compile down to line 60.

Nondesending.java:60: error: 'else' without 'if'
     else{
     ^
Nondesending.java:69: error: reached end of file while parsing
}        
 
Carey Brown
Bartender
Posts: 10980
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This is not a properly formatted if() statement. First off, the entire boolean expression should be enclosed in parenthesis. The '=' is an assignment operator, use '==' to compare to values. 'or' is not a Java keyword, use '||'. Having ';' embedded int the expression will cause the following block to always be executed, rather than based on the outcome of the expression.
 
Carey Brown
Bartender
Posts: 10980
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On line 49 you have an open brace '{' which is the start of a block. On line 53 you should have the closing brace '}'.
 
Joe Robinson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Nondesending.java:49: error: illegal start of expression
    { if (number1 == number2) || (number1 == number3) || (number2 == number3);
                              ^
Nondesending.java:49: error: not a statement
    { if (number1 == number2) || (number1 == number3) || (number2 == number3);
                                                      ^
Nondesending.java:58: error: illegal start of expression
     if (number1 < number2) || (number1 < number3); then
                            ^
Nondesending.java:60: error: 'else' without 'if'
     else{
     ^
Nondesending.java:69: error: reached end of file while parsing
}        
^
5 errors

----jGRASP wedge: exit code for process is 1.
----jGRASP: operation complete.
 
Carey Brown
Bartender
Posts: 10980
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

See previous comment about if().

  • There is no 'then' or 'end' keywords in java.
  • You have a closing block brace '}' with no corresponding open brace.
  • You are adding the numbers together which will result in an int. You can't assign an int to a String.
  •  
    Carey Brown
    Bartender
    Posts: 10980
    87
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    A typical if() construct looks like this
     
    Joe Robinson
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I honestly do appreciate your help on this problem.  i think to more fully understand how this should look i would have to see a before and after.  This assignment was due like 2 weeks ago, i was just trying to get a better understanding of how it should look when completed as it would help me in further assignments.

     
    Joe Robinson
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    OK i have gotten to the point where i can enter the numbers but now it will not output them after the 3rd number is entered
     
    Carey Brown
    Bartender
    Posts: 10980
    87
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Joe Robinson wrote:I honestly do appreciate your help on this problem.  i think to more fully understand how this should look i would have to see a before and after.  This assignment was due like 2 weeks ago, i was just trying to get a better understanding of how it should look when completed as it would help me in further assignments.


    We don't do your assignment for you. We are here to help and guide you in coming up with your own solution.

    Do you have a Java book that you're working from? You should be able to find info on the syntax for boolean expressions and conditional statements (i.e. if()). There's also plenty of online tutorials. Example: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html
     
    Carey Brown
    Bartender
    Posts: 10980
    87
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Close, but missing braces

     
    Joe Robinson
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I think that i have it.  Thanks so much
     
    Carey Brown
    Bartender
    Posts: 10980
    87
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    outputStr=Integer.toString(number1+number2+number3);

    Adding the integers: 1 + 5 + 4
    results in: 10

    Adding the integers: 4 + 1 + 5
    is also: 10

    This what your output string will contain.

    If you want your output string to have the list of the three integers, then
    outputStr = num1Str + " " + num2Str + " " + num3Str;
     
    Joe Robinson
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Ok i see how that is adding the numbers instead of putting them in order.
     
    Marshal
    Posts: 80254
    428
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    . . . and welcome to the Ranch
    reply
      Bookmark Topic Watch Topic
    • New Topic