1,171 Posted Topics

Member Avatar for Mz. Jackee

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 …

Member Avatar for Mz. Jackee
0
208
Member Avatar for asifalizaman

>who learn java with me if any one then ask me question ??????????????????? I want. My question: is your question mark key broken?

Member Avatar for <M/>
0
215
Member Avatar for emaellie

`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.

Member Avatar for emaellie
0
249
Member Avatar for chocolatte.lavista

>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 …

Member Avatar for tinstaafl
0
283
Member Avatar for TIM_M_91

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 …

Member Avatar for IIM
0
635
Member Avatar for musikluver4

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 …

Member Avatar for stultuske
0
301
Member Avatar for StefanRafa0

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).

Member Avatar for bguild
0
439
Member Avatar for aVar++
Member Avatar for pxmur76

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)]

Member Avatar for stultuske
0
1K
Member Avatar for Nakeo

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 …

Member Avatar for tux4life
0
442
Member Avatar for RozenKristal

>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 …

Member Avatar for RozenKristal
0
297
Member Avatar for toldav

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 …

Member Avatar for tux4life
0
335
Member Avatar for ChevaneHeadChefCooke

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.

Member Avatar for tux4life
0
444
Member Avatar for paigewms

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 …

Member Avatar for tux4life
0
823
Member Avatar for engrjd91
Member Avatar for smilesprower

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 …

Member Avatar for JamesCherrill
0
218
Member Avatar for nova4005

>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 …

Member Avatar for bguild
0
549
Member Avatar for richard.haines.39

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`. …

Member Avatar for richard.haines.39
0
862
Member Avatar for michelleruth

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 …

Member Avatar for michelleruth
0
2K
Member Avatar for andrew.ferrebee

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 + …

Member Avatar for radhakrishna.p
0
240
Member Avatar for homeboy
Member Avatar for tux4life

This issue is easiest explained by a screenshot: ![rmas_screenshot](/attachments/large/1/rmas_screenshot.png "rmas_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 …

Member Avatar for Dani
1
299
Member Avatar for engrjd91

>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 …

Member Avatar for engrjd91
0
138
Member Avatar for tux4life

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 …

Member Avatar for Dani
0
228
Member Avatar for engrjd91

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

Member Avatar for engrjd91
0
143
Member Avatar for sufu

>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).

Member Avatar for tux4life
0
109
Member Avatar for tux4life

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 …

Member Avatar for Dani
0
166
Member Avatar for Louie_Rave

>[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 …

Member Avatar for Louie_Rave
0
509
Member Avatar for london-G

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.

Member Avatar for tux4life
0
312
Member Avatar for jalpesh_007

>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 …

Member Avatar for jalpesh_007
0
194
Member Avatar for rchrist3

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*.

Member Avatar for tux4life
0
278
Member Avatar for awfootball7

[Arrays.sort(int[])](http://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html#sort(int[])) should do the job.

Member Avatar for stultuske
0
329
Member Avatar for hg_fs2002

Use the escape sequence: `'\'`. Example: char c = '\'; // store a backslash

Member Avatar for tux4life
0
132
Member Avatar for cisumma

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 …

Member Avatar for deceptikon
0
165
Member Avatar for Violet_82

>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 …

Member Avatar for Violet_82
0
532
Member Avatar for emmas4impact

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***.

Member Avatar for softswing
0
345
Member Avatar for supertechnewbie

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 …

Member Avatar for tux4life
0
149
Member Avatar for lewashby

Also take a look here: http://eternallyconfuzzled.com/tuts/languages/jsw_tut_pointers.aspx

Member Avatar for lewashby
0
246
Member Avatar for StefanRafa0
Member Avatar for stultuske
0
205
Member Avatar for gsfdg
Member Avatar for tux4life

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 …

Member Avatar for Ancient Dragon
0
179
Member Avatar for dendenny01

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.

Member Avatar for tux4life
0
4K
Member Avatar for hg_fs2002

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) …

Member Avatar for tux4life
2
680
Member Avatar for mehmud

>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.

Member Avatar for tux4life
0
937
Member Avatar for efth

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 …

Member Avatar for efth
0
17K
Member Avatar for cerealBoxx

>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 …

Member Avatar for ddanbe
0
144
Member Avatar for jalpesh_007

In Java you have **primitive** and **reference** types. **Primitives** are *boolean*, *char*, *byte*, *short*, *int*, *long*, *float*, *double*. Anything else is a **reference** type.

Member Avatar for jalpesh_007
0
277
Member Avatar for javaid iqbal

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 }

Member Avatar for harinath_2007
-2
113
Member Avatar for awfootball7

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 …

Member Avatar for gon1387
0
457
Member Avatar for suren3

That material is covered by any basic course in C. Do a Google search and/or check your course notes.

Member Avatar for akashgupta1990
0
155

The End.