• Post Reply Bookmark Topic Watch Topic
  • New Topic

error message debug  RSS feed

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm very new to java code I'm currently learning about loops I've tried to write this for a statement in the program I'm making but its not working. I keep getting this message

LoanQualifier.java:26: error: illegal start of expression
if (salary >0||<=250000)
^
LoanQualifier.java:28: error: illegal start of type
if (yearsOnJob >0||<50)


I'm using Jgrasp for a complier
 
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
brandon mac wrote:I'm very new to java code I'm currently learning about loops I've tried to write this for a statement in the program I'm making but its not working. I keep getting this message

LoanQualifier.java:26: error: illegal start of expression
if (salary >0||<=250000)
^
LoanQualifier.java:28: error: illegal start of type
if (yearsOnJob >0||<50)


I'm using Jgrasp for a complier


If(salary >0 || salary is <50)
The compiler don't know what is being compared with 50. you have to provide that information. Consider the part after || a new expression and >50 alone makes no sense to the compiler
 
Bartender
Posts: 4002
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

If you are starting Java you should use Java compiler (javac) comes with JDK to get started things and learn basics first.

Your if condition is missing variable in second comparison after OR (||) operator.

i.e.: if (salary > 0 || salary <= 250000)

You may walk through our Java-FAQ to learn some of the basics involved.
 
brandon mac
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I'm wondering by adding the second part does that act as the AND/ OR for the statement or does it change the criteria
 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand what "adding the second part" means there. What you first posted isn't valid Java -- as the error messages said -- and so it doesn't mean anything. There are no criteria there as far as the compiler is concerned. What the others posted in response is valid Java.
 
brandon mac
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the confusion,

What I'm trying to ask is does it mean the same thing even though the part i wrote is not valid code will it accomplish the same thing in the end now that you have identified the problem
 
Paul Clapham
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like I said, invalid code won't accomplish anything. You can't compile it, you can't run it.

Probably what you want to ask is "Will the valid code posted by those other people do what I meant when I wrote the invalid code?" If that's the case then what I'm trying to say is that you should move on and ask whether the valid code does what you want. Because we don't actually know what you wanted the code to do, we just have some invalid code which suggests what you might have wanted to do.

If you think I'm being unnecessarily fussy and it should be obvious what you wanted anyway, I'm doing this because it's possible to write confusing code in both invalid and valid forms. For example there are languages in which "If X not = 3 and 4" is valid code, but it doesn't mean what most people think it means. So my recommendation is to forget the invalid code, just take your requirements (which really I'm pretty sure I understand) and convert them into valid code.
 
Paul Clapham
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the answer is no, none of the code posted does what you want. This code which is a minor modification of your original attempt?



It produces true for every possible value of salary. I'm pretty certain you didn't want that. But suppose salary is 1 million. Then since it's greater than 0, that's okay. And suppose salary is -100. Then since it's less than or equal to 250000, that's okay too. Remember that for "A or B" to be true, you only have to have one of A and B be true. My bet is that you want this:

 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
brandon mac wrote:What I'm trying to ask is does it mean the same thing even though the part i wrote is not valid code will it accomplish the same thing in the end now that you have identified the problem

Generally, it works best if you tell us what you are trying to do. Don't use java terms, don't use programming terms, use plain old English. That is the first step in writing a program anyway - describe the problem in a natural language. Then you refine the steps. 5-6 times, making them simpler and clearer.

So...tell us what you meant to do.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!