Browsing 7239 questions and answers with Jon Skeet

If else error I don't understand this error

I don't understand this error is it logical error or something else here is the coding " this program should convert riyal to currency that is chosen by the user using multiway...
Jon Skeet
people
quotationmark

You aren't marking the start and end the bodies of your if statements - wihch means they're just single statements. You've currently effectively got: if(opp==1) { c=riyal*0.267; } System.out.print(riyal+" Riyals is converted to "+c"... more 5/1/2015 9:07:25 AM

people

Is there a way to cast type parameter?

Can I use type parameter as implementing specific interface at Runtime without Reflection? The following pseudocode is what I want to do. void Run1<T> () { // ... ...
Jon Skeet
people
quotationmark

No, I don't believe there's a simple way you can do that. If you're in control of all the code, you could have a public version of Run2 with the constraint, but a private implementation of Run2 without the constraint, which you call from... more 5/1/2015 6:21:45 AM

people

not adding a comma at the end in java

I want to print out the values in this array of sorts with each value being comma separated in java. However, I do not want my last value to have a comma after it. for (double...
Jon Skeet
people
quotationmark

If output.getPvalues() returns an array, you could use: double[] values = output.getPvalues(); for (int i = 0; i < values.length(); i++) { System.out.print(values[i]); if (i != values.length - 1) { ... more 5/1/2015 6:17:50 AM

people

Database INSERT not adding data to table

I am trying to run two queries, one to create a table and another to insert some value in it. Table is getting created but value is not getting added to the table. stmt =...
Jon Skeet
people
quotationmark

Apparently you've called c.setAutoCommit(false) ... but then you haven't committed the update. So no, that won't have updated the database. Just use c.commit(); after the update - or turn auto-commit back on instead. If you were... more 5/1/2015 6:13:02 AM

people

Unsure why it states "No overload for method takes 0 arguments"

I'm supposed to take the user's input and re-print it into alternate capital letters. I took the string and converted it into a char array and I'm trying to do it by using the...
Jon Skeet
people
quotationmark

You're calling char.ToLower - which is a static method accepting the relevant character as a parameter, and optionally a CultureInfo. So you probably want: y = char.ToUpper(letter); and y = char.ToLower(letter); Note that your loop... more 4/30/2015 7:30:41 PM

people

Java Time Stamp unicode issue

While I'm trying to pass a timestamp as param for a post request, on Arabic phones etc., it seems to convert it into a unicode rather than a long. Can anyone explain me any...
Jon Skeet
people
quotationmark

Just use String.valueOf(long) instead: String timeStampString = String.valueOf(System.currentTimeMillis() / 1000L); Unlike String.format, that will always format using "regular" digits '0' to '9'. more 4/30/2015 7:17:59 PM

people

Trying to run jar file but getting cannot find class

I am trying to run a jar file from the Win7 command line, but am getting the dreaded could not find or load main class PRCreateExecution. I can successfully build the jar file...
Jon Skeet
people
quotationmark

Firstly, it sounds like you're not actually trying to run your jar file at all. You're not mentioning it anywhere on your command line. Secondly, it looks like your classpath is wrong - it should probably be java -cp... more 4/30/2015 6:53:42 PM

people

How to read/write .dat file within Jar file?

Okay this maybe very similar to a few questions out there and I've been looking all over, but can't manage to fix this. This is the only thing preventing my .jar from compiling...
Jon Skeet
people
quotationmark

You can get an InputStream using Class.getResourceAsStream (or ClassLoader) using a class or ClassLoader that "knows" about that jar file. If you're finding that Class.getResourceAsStream() isn't working for you, you're probably passing... more 4/30/2015 5:47:39 PM

people

Java 8 LocalDate determining the year of a yearless Feb 29 date?

My colleague and I have an interesting problem. We work with an old system that only returns date data in the format ddMMM. If the day/month is in the past for the current year,...
Jon Skeet
people
quotationmark

Parse the value as a MonthDay, as that's what you've got. If the month-day is not February 29th, just handle it as normal If it is February 29th, you need to special-case it: Determine whether the current year is a leap year with... more 4/30/2015 5:29:42 PM

people

Delegate evaluate order

I was trying to bind following operation on delegates: 2*2+2 this should give of course 6 but my example give 8 I thought that all delegates used here will not be evaluated...
Jon Skeet
people
quotationmark

You're not evaluating 2 * 2 + 2. You're evaluating 2 * (2 + 2) The fact that delegates are involved is irrelevant here - you're always evaluating them as soon as they're returned anyway. You can effectively rewrite the code as: static... more 4/30/2015 1:58:39 PM

people