1,171 Posted Topics
Re: Take a look at the [System.Console](http://msdn.microsoft.com/en-us/library/system.console.aspx) class. There are two basic things you need to know: **Input** and **Output**. I suggest that you take a look at [System.Console.WriteLine(String)](http://msdn.microsoft.com/en-us/library/xf2k8ftb.aspx) (Output) first, then proceed by checking out [System.Console.ReadLine()](http://msdn.microsoft.com/en-us/library/system.console.readline.aspx) (Input). Of course there's more, but start out with these and see how far … | |
Re: >who learn java with me if any one then ask me question ??????????????????? I want. My question: is your question mark key broken? | |
Re: `int main(void)` is also acceptable and portable. I think you should even prefer it to `int main()` if the intent is to not have any parameters. | |
Re: >so i am not really understand how to use an array. Self-teaching is an important skill that every programmer should posses. "How to use an array" can be interpreted in several ways. You should clarify on that. What in specific are you encountering trouble with? Is it the array syntax … | |
Re: The following piece of code will result in a compile-time error: BigInteger c = a.nextBigInteger(); sum += c; If the intent is to add BigIntegers then `sum` should be a BigInteger too. Here's a fix: BigInteger sum = BigInteger.ZERO; // ... sum = sum.add(a.nextBigInteger()); // assume that 'a' has type … | |
Re: Moreover in Java you can only use expressions that evaluate to a value of type `boolean` to control statements like if, while, do-while **[1]** (unlike in C/C++). int i = 1; if (i == 1) { // valid since i == 1 evaluates to a boolean value //... } if … | |
Re: I think a [FocusListener](http://docs.oracle.com/javase/tutorial/uiswing/events/focuslistener.html) is what you need. Also re-read [this post](http://www.daniweb.com/software-development/java/threads/446807/save-in-file-and-read-from-it#post1928659). | |
Re: Why using a KeyListener if you can add an ActionListener to your JTextField? [[Relevant link](http://stackoverflow.com/questions/4419667/detect-enter-press-in-jtextfield)] | |
Re: I vote for the enum approach, and in case there's need for a Map, consider using [EnumMap](http://docs.oracle.com/javase/6/docs/api/java/util/EnumMap.html). It has perfect hashing and is extremely compact because internally it represents the elements of the enum using a bit vector. @JamesCherril: Your suggestion does not take the [equals](http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html#equals(java.lang.Object)) and [hashCode contract](http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html#hashCode()) into … | |
Re: >wat confused me was least deep leaf has depth 2. Why so, it should be depth 3 if height is 3. No, it shouldn't, there's a difference between depth of a *node* and height of a *tree*. The depth of a node is the number of edges on the path … | |
Re: Use a [Set](http://docs.oracle.com/javase/6/docs/api/java/util/Set.html) datastructure to keep track of the numbers already guessed. Everytime the user makes a guess, you check if the user has guessed this number already by looking if that number is contained in the set. If not, then the user hasn't guessed that number before and you … | |
Re: I don't get any compiler error when trying to compile the piece of code that you've posted. Please post the piece of code that results in the compiler error you've described. | |
Re: In addition to what's been said, my opinion is that you should prefer to not have **unused import** statements in your code. (Not that it will differ in terms of performance though). Also my preference is that you **specify exactly** which class you want to use instead of using the … | |
Re: What is the download link and where did you get it from? | |
Re: You probably declared your `faceCombo` something like: JComboBox faceCombo = new JComboBox(); Even though it will work, you used a **raw type**: JComboBox can take a **type parameter** that specifies what the type is of the items you want to put in it. From the code snippet you posted it … | |
Re: >I don't think I can use charAt(i) to compare the three consecutive 1's, but I don't know what I can use to test if there are three consecutive 1's in the string. You *could* use [charAt()](http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#charAt(int)) but it is tedious to do so compared to using [contains()](http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#contains(java.lang.CharSequence)). Note that the … | |
Re: You're getting an ArrayIndexOutOfBoundsException because you are trying to access indexes that are not valid in your array. The array you are iterating over is smaller than 10 elements, yet you are adding 10 to every i, which is guaranteed to be out of bounds for any `i >= 0`. … | |
Re: You can make use of the left shift operator: **<<**. 2^2 = `2 << 1` 2^3 = `2 << 2` 2^4 = `2 << 3` etc. It works as follows: the decimal number 2 can be represented in binary as *00000010*. The **<<** operator shifts all the bits to the … | |
Re: Exact error message (when compiling from the command line): C:\Users\mvmalderen\Desktop>javac Calculator.java Calculator.java:31: error: ')' expected case 2: A = (P *(1 + (r/n))Math.pow(n,t)-P); ^ Calculator.java:31: error: illegal start of expression case 2: A = (P *(1 + (r/n))Math.pow(n,t)-P); ^ Calculator.java:31: error: ';' expected case 2: A = (P *(1 + … | |
Re: I think the OP wants to know how to do a reflective method call. | |
This issue is easiest explained by a screenshot:  The title of the [thread](http://www.daniweb.com/web-development/web-design-html-and-css/threads/64334/help-on-clear-text-in-input-) linked to contains the `<input>` starttag: *Help on clear text in **<input>** !!*. I'm wondering what would happen if someone inserted an `<img>` tag in a thread title... **Edit:** Perhaps the solution is not to … | |
Re: >I have the above code and its thorwing an exception of numberformatException. What is wrong with this code .. kindly help me out. Which values did you enter as input? **Edit:** look closely at the following two lines of code: String s = ("1= add, 2 = subtract"); int op … | |
Hello, I'm mostly active in the Java forums these days, and often I find the desire to link to a method in the Java API, but the markdown syntax doesn't seem to handle the URL format quite well. Here's an example of a URL that I was recently trying to … | |
Re: If you want to use an integer as a key in a Map you'll need to use a **primitive wrapper**. Here's an example of that: Map<Integer, String> map; Note that the following is not valid: Map<int, String> map; // invalid | |
Re: >first create jsp page and insert your database code into it.also post what you have done so far... You should **NEVER** write business and persistence logic directly inside a JSP page. Take a look at: [JSP database connectivity according to Model View Controller (MVC) Model 2](http://www.daniweb.com/web-development/jsp/threads/141776/jsp-database-connectivity-according-to-model-view-controller-mvc-model-2). | |
When quoting a user, the username of the quoted user isn't shown. The page about [markdown syntax](http://www.daniweb.com/community/syntax) seems to imply that this isn't possible in a syntax supported way. I think it would contribute to clarity to also be able to syntactically specify the username of the quoted user. I … | |
Re: >[line 18]: // I got a problem with this here. It's supposed to be a command that reads a char input. But I don't know how to do it too. You can pick-off the first character in the String. [readLine()](http://docs.oracle.com/javase/6/docs/api/java/io/BufferedReader.html#readLine()) returns a String, and the String class has a method … | |
Re: An important thing, not directly related to your question, but related to connecting to databases from an application in general is that you shouldn't hard-code the connection details into the application. It would be an improvement to store the database connection parameters in say, a configuration file, for example. | |
Re: >I hope everyone is aware that StringBuilder is superior to StringBuffer. For those who aren't, the reason is that StringBuffer synchronizes on every call, while StringBuilder doesn't, therefore StringBuffer is thread-safe, and StringBuilder isn't. Truth is that most of the time you don't need the thread-safety offered by StringBuffer, so … | |
Re: You should run PetTest **[1]** instead of Pet. If you're on the command line this means that you have to invoke as: `java PetTest` (*after* compiling). Also you have to remove what's on line 11, its syntax is invalid. **[1]** Because this class contains the *main method*. | |
Re: [Arrays.sort(int[])](http://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html#sort(int[])) should do the job. | |
Re: Use the escape sequence: `'\'`. Example: char c = '\'; // store a backslash | |
Re: What you refer to as "ternary expression" is actually called the ***conditional operator*** in Java. Terminology aside, you can use the conditional operator as a shorthand for the following: int a; if (condition) a = expression1; else a = expression2; Using the conditional operator, the above can be rewritten as … | |
Re: >I mean the seed is where the random generator is supposed to start generating numbers from? *The class uses a 48-bit seed, which is modified using a **linear congruential formula**.* (Source: Java API - [java.util.Random](http://docs.oracle.com/javase/6/docs/api/java/util/Random.html)) ***This is a linear congruential pseudorandom number generator**, as defined by D. H. Lehmer and … | |
Re: Look at the API documentation for [getSystemResource](http://docs.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html#getSystemResource(java.lang.String)): **Returns**: *A URL object for reading the resource, **or null if the resource could not be found***. | |
Re: The reason is that there's still data in the input stream after the exception has occurred. You can fix it by reading a line when an exception occurs, using `keyboard.nextLine()`. Also it seems like your `noException` flag is redundant. Play a bit with the following piece of code: while (num … | |
Re: Also take a look here: http://eternallyconfuzzled.com/tuts/languages/jsw_tut_pointers.aspx | |
Re: What is the output you are getting now, and what is your desired output? | |
Re: Your code is missing an ending brace on line 60. | |
How to reproduce: 1. Open up two tabs, load the member activity stream in the first, in the second load another random Daniweb page. 2. Log out from the second tab. 3. Switch back to the first tab and notice that the stream keeps streaming. I'm using Google Chrome version … | |
Re: Have you started already? If not, why so? What in particular are you having difficulties with? As a hint: modulo 10, division by 10, multiplication by 10; you can pretty much solve your task using these operations. | |
Re: Try the following: *Double.parseDouble("0x0.DAB789B**p0**")*. The **p0** means that the part on its left side is multiplied by **(** 2 ^ **0** **)** = **1**. Sources: * [Double.valueOf](http://docs.oracle.com/javase/6/docs/api/java/lang/Double.html#valueOf(java.lang.String)) (Java API - referred to from the API documentation of [Double.parseDouble](http://docs.oracle.com/javase/6/docs/api/java/lang/Double.html#parseDouble(java.lang.String))) * [Hexadecimal Floating-Point Literals](https://blogs.oracle.com/darcy/entry/hexadecimal_floating_point_literals) (Blog - Joseph D. Darcy) * [Floating-Point Literals](http://docs.oracle.com/javase/specs/jls/se5.0/html/lexical.html#3.10.2) … | |
Re: >Should wallet extend coin? Whenever in doubt apply the **IS A**-test: *Wallet **IS A** Coin?* (or rephrased: ***IS** Wallet **A** Coin?*) If the answer to that question is no, then you shouldn't. | |
Re: Here's a link to the API documentation for it: [http://docs.oracle.com/javase/6/docs/api/java/util/EventObject.html#getSource()](http://docs.oracle.com/javase/6/docs/api/java/util/EventObject.html#getSource()) As you'll notice its return type is Object, so you'll need to cast to whatever the type of your event source is. Before doing so it is always a good idea to use the **instanceof** operator to check if casting … | |
Re: >I tried to convert it to both int and string but then I got the error "can't implicitly convert void to string/int". What to do? My post tries to clarify on previously given information. You defined your `ReturnPattern` method as follows: *static **void** ReturnPattern(int n)*. Then you try to use … | |
Re: In Java you have **primitive** and **reference** types. **Primitives** are *boolean*, *char*, *byte*, *short*, *int*, *long*, *float*, *double*. Anything else is a **reference** type. | |
Re: The method returns an **int**, you can simply use `System.out.println()`. Here's a simple demo program: public class Test { public static void main(String[] args) { int[] a = {1, 2, 3, 4, 5}; System.out.println(findMaxPosition(a)); } // put your findMaxPosition method here } | |
Re: The method signature of your `checkMoney` method looks like this: public void checkMoney(int dollars, int cents) On lines 79 (`x.checkMoney();`) and 84 (`y.checkMoney();`) you didn't pass in arguments. Hence you'll get a compilation error *actual and formal argument lists differ in length*. The actual argument list in this context is … | |
Re: That material is covered by any basic course in C. Do a Google search and/or check your course notes. |
The End.