Posts
 
Reputation
Joined
Last Seen
0 Reputation Points
0% Quality Score
Upvotes Received
0
Posts with Upvotes
0
Upvoting Members
0
Downvotes Received
1
Posts with Downvotes
1
Downvoting Members
1
1 Commented Post
0 Endorsements
Ranked #4K
~24.6K People Reached
Favorite Tags

46 Posted Topics

Member Avatar for ghfeyn

First: import java.io.*; Then you need to read from the console: try { //create a buffered reader that connects to the console, we use it so we can read lines BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //read a line from the console String lineFromInput = in.readLine(); //create an print writer …

Member Avatar for JamesCherrill
0
6K
Member Avatar for emman

Did you try using Application.Exit(). Call this function when you want the entire application to end. For more help, [url]www.NeedProgrammingHelp.com[/url]

Member Avatar for M.Waqas Aslam
0
168
Member Avatar for verbena1

To add a new node to the end of the linked list you should try: [CODE]Node newNode = new Node(characterObject); if(length == 0) { firstNode = tailNode = newNode; } else { tailNode.next = newNode; tailNode = newNode; } length++;[/CODE]The problem with your code is that you update tailnode in …

Member Avatar for Gsterminator
0
318
Member Avatar for perlsu

Try this code [CODE] double num = 1001.27124; double newNum = Math.round(num*100.0)/100.0; System.out.println (newNum); //prints 1001.27 [/CODE] It works because *100 shifts the numbers to the left twice. Then the round is applied. Then we divide by 100 to shift twice right. For more help, [url]www.NeedProgrammingHelp.com[/url]

Member Avatar for mubin_89
1
4K
Member Avatar for Java John needs

Your error lies in the following code: [CODE]while (!phrase.equals("quit")) phrase = scan.nextLine();[/CODE] This reads lines but only saves the last line in phrase. Each time it overwrites the last line with the new line. Also, your loop is stopping too late. It includes quit as a phrase. The correct code …

Member Avatar for NormR1
0
279
Member Avatar for jaxy

Suppose you want to generate 50 unique random numbers from 0 to 100. [CODE] //Create an array of size 100 that remembers which integers are taken boolean[] taken = new boolean[100]; //start count at 0 int count =0; //create random gen Random r = new Random(); //create array to hold …

Member Avatar for neelkris
0
2K
Member Avatar for Finalmadness

Did the professor tell you what the Gift class is supposed to represent? If this program is about converting currency, what does a gift have to do with converting currency? You mentioned that the Gift class must hold the total. You could use the Gift class below and create a …

Member Avatar for NPH
0
218
Member Avatar for iamthwee

You could create a batch file (.bat). This answer is for Windows computers. It is not an executable but it is very simple to make. Suppose you main method is in the class MyTest. Then create a file called MyJavaRun.bat. (The name is arbitrary) Inside the file write: [CODE]java MyTest …

Member Avatar for iamthwee
0
568
Member Avatar for Montrell274

The scanner interface can be used to read lines, tokens, etc. Suppose you want to open a file named "c:\test.txt" using the Scanner: [CODE]Scanner sc = new Scanner(new File("c:\\test.txt"));[/CODE]To read all the lines from the file using the created scanner: [CODE]while(sc.hasNextLine()) { String scLine = sc.nextLine(); //process line }[/CODE]What is …

Member Avatar for NPH
0
106
Member Avatar for jasmin_java

Take $123.30. [COLOR=Blue][B]1.[/B][/COLOR] First you need to separate the dollars and the cents using the substring method of the String class (see code below). [COLOR=Blue][B]2.[/B][/COLOR] How do you convert a hundreds digit? Just put "Hundred" afterwards: 1xx = > One Hundred xx [COLOR=Blue][B]3.[/B][/COLOR] How do you convert a tens digit? …

Member Avatar for NPH
0
211
Member Avatar for Melotron

Melotron, Here is an example of the code you need: [CODE]import javax.swing.JOptionPane; public class Test { public static void main(String[] a) { //get first string from user String indata1 = JOptionPane.showInputDialog("Enter text"); //get second string from user String indata2 = JOptionPane.showInputDialog("Enter text"); //check length if( indata1.length() > indata2.length()) { System.out.println("The …

Member Avatar for jwenting
0
652
Member Avatar for OllieFalle

OllieFalle, Here are a few things that seem incorrect to me (correct me if I am wrong): [B]1.[/B] Your method called userInput shown below has problems [CODE]public void userInput () { System.out.println("Enter a sequence of notes: "); String sent = Keyboard.readString(); StringTokenizer st = new StringTokenizer(sent); String word; while (st.hasMoreTokens()) …

Member Avatar for OllieFalle
0
141
Member Avatar for tdizzle342

Run this code below. See the comments for an explanation. This should help understand what you need to use. [CODE]import javax.swing.*; import java.awt.*; class TestPanel extends JPanel { //paint function public void paint(Graphics g) { //cast to Graphics2D Graphics2D g2D = (Graphics2D)(g); //set stroke int lineWidth = 5; g2D.setStroke( new …

Member Avatar for NPH
0
152
Member Avatar for glamo

glamo, See Chapter 7 in this page: [url]http://www.jeffheaton.com/ai/[/url] You need to understand Neural Networks. I would suggest to read the other chapters. :?: For more help, [url]www.NeedProgrammingHelp.com[/url]

Member Avatar for nordmann
0
193
Member Avatar for young

I would suggest to use a 3x3 two dimensional array. Maybe something like [CODE]char player[][] = new char[3][3];[/CODE]Then when player 1 wants to use cell (1,2) write: [CODE]player[1][2] = '1';[/CODE] :?: For more help, [url]www.NeedProgrammingHelp.com[/url]

Member Avatar for NPH
0
117
Member Avatar for tejtan

To check if someone is already in the room use the following code: [CODE]boolean isRoomOccupied(int floor, int room) { if( array[floor][room] == null ) return true; else return false; }[/CODE] When someone checks out call this function [CODE]void checkOut(int floor, int room) { array[floor][room] = null; }[/CODE]It is very important …

Member Avatar for NPH
0
120
Member Avatar for Chipsncoke

Here is a working example of what you need. Basically it takes commands like 'add node' with name "Child1" to node with name "Parent1". The root must always be referred to as "root". Run the code and read the comments. Should be easy to use/modify. [CODE]import javax.swing.*; import javax.swing.tree.*; import …

Member Avatar for Chipsncoke
0
240
Member Avatar for jaxy

The while loop only runs one time because of the statement [CODE]return itemNo ;[/CODE]Once that statement executes the loop (and the entire method) are ended. Take out the return and it should work. Why are you putting a return there anyways? :cool: For more help, [url]www.NeedProgrammingHelp.com[/url]

Member Avatar for jaxy
0
177
Member Avatar for kyakobi84

Have you tried this code: [CODE]Dim strBinary As String = "11111111" Dim intValue As Integer Dim iPos As Integer Dim iVal As Integer For iPos = 0 To strBinary.Length - 1 iVal = strBinary.Substring(strBinary.Length - iPos - 1, 1) intValue = intValue + iVal * 2 ^ iPos Next[/CODE] You …

Member Avatar for kyakobi84
0
148
Member Avatar for glamo

There are many problems: 1. Fix mispelling/case errors. 2. There is no unsigned keyword 3. main must be public static 4. f has no return type 5. readLine() returns String not int 6. I have no idea what you mean by the following line: System.out.println("you have entered names of "+name[i=String[i].length()>=0]+"these …

Member Avatar for NPH
0
162
Member Avatar for Blazer

Why do you need to store all the lines? Couldn't you just maintain the average of the numbers in a variable. For example, [CODE]create a total & amount variable (for the average... average = total/amount) double total =0; double amount=0; //for each line in the file while ((line = input.readLine()) …

Member Avatar for boyzz
0
181
Member Avatar for kokopo2

Override the paint method and use the translate method of the Graphics object. Remember that translate(100,100) doesn't mean goto point 100,100. It means move to the right 100 and move down 100. [CODE] public void paint(Graphics g) { //draw circle drawCircle(g); //move left and down by 100 g.translate(100,100); //draw another …

Member Avatar for kokopo2
0
104
Member Avatar for shuchi_jain

Check out these two links. Hope it helps. [url]http://www.falkhausen.de/en/diagram/html/javax.swing.JComponents.html[/url] [url]http://www.falkhausen.de/en/diagram/html/java.awt.Components.html[/url] For more help, [url]www.NeedProgrammingHelp.com[/url]

Member Avatar for jwenting
0
243
Member Avatar for kharri5

Your image is not being found. Probably the directory "C:/MyDocuments/MemoryGame/woodTable.gif"; doesn't exist. If its in your documents folder then the correct directory would be: C:/Documents and Settings/YOUR WINDOWS USER NAME HERE/My Documents/woodTable.gif. For more help, [url]www.NeedProgrammingHelp.com[/url]

Member Avatar for kharri5
0
2K
Member Avatar for perlsu

You can use the String classes replaceAll method. Here is an example: [CODE]String str = "Hello blank"; String newStr = str.replaceAll("blank", "Jim") ; System.out.println(newStr); //prints "Hello Jim"[/CODE] For more help, [url]www.NeedProgrammingHelp.com[/url]

Member Avatar for NPH
0
167
Member Avatar for katew

Firstly, The line with the code [CODE]if((tokens.hasMoreTokens()) );[/CODE]is basically useless. This checks if there are tokens and does nothing. What you want is [CODE]if((tokens.hasMoreTokens()) ) { //put code here }[/CODE]Also, you might want to use the trim() function when getting tokens. This cleans out the string of weird spaces at …

Member Avatar for katew
0
309
Member Avatar for perlsu

You received a NullPointerException because the array [B]possibleseq [/B] is always null and you end up using it in your code. The best solution is to create an ArrayList by writing [CODE][B]ArrayList [/B]possibleseq= new [B]ArrayList[/B]();[/CODE] then add your strings into it by writing: [CODE]possibleseq.add("someText");[/CODE] Then to get the 11th item …

Member Avatar for perlsu
0
130
Member Avatar for boyzz

Each row contains a persons info. The best thing to do is create a class that holds each row. Here is an example: [CODE]class PersonInfo { private String name; private int age; private String address; public PersonInfo(String name, int age, String address) { this.name=name; this.age=age; this.address=address; } } [/CODE] Then …

Member Avatar for boyzz
0
326
Member Avatar for indianscorpion2

Polymorphism means many forms. The idea of polymorphism is very important in OOP. Lets look at Java's IO classes (they use a lot of this concept). The code below is legal: [CODE]//The inputstream r will get its input from a file. InputStream r = new FileInputStream("someFile.txt");[/CODE]The code below is also …

Member Avatar for NPH
0
120
Member Avatar for fuehrer

== has many meanings [B]1.[/B] When comparing simple data types (int, char, double, bool, etc), == compares the value of the two. [CODE]int x = 1; int y = 2-1; System.out.println( x == y ); // **** [B]prints true[/B] ****[/CODE] [B]2. [/B] When comparing two object references, it compares the …

Member Avatar for fuehrer
0
248
Member Avatar for MastaPho

Here is a quick & simple example of showing an image in java. The most import code is in the paint method. In this case, we are redefining the way a usual panel draws itself. The class ImagePanel does just this. The other class just uses this panel in a …

Member Avatar for JeffHeaton
0
213
Member Avatar for nishad

[B]For the first problem,[/B] you must use two for loops. Lets call the horizontal direction i and the vertical direction j. Notice how the #'s change [B]10 [/B] times from 10 to 100 in direction i Notice how the #'s change [B]10 [/B] times from 10 to 210 in direction …

Member Avatar for NPH
0
116
Member Avatar for visual one

1. Shouldn't TotalBalance start off with the initial balance? [CODE]double TotalBalance = initialBalance //not: double TotalBalance = 0[/CODE] 2. When there are insufficient funds for a check, shouldn't the original transaction be cancelled and only the overdraft charge applied? [CODE]balance = (balance) - Fee; //not: balance = (balance + transaction) …

Member Avatar for server_crash
0
431
Member Avatar for freesoft_2000

Here is a test class to get you started. I think this should help you. [CODE]import java.io.*; import java.util.*; class Bytes { public static void main(String[] args) { try { [B]//create byte output stream[/B] ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); [B]//creat object output stream and connect [/B] him to the byte …

Member Avatar for DeepZ
0
321
Member Avatar for kittie

This is an simple example on implementing the ActionListener interface. [CODE]class MyClass implements ActionListener { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "ACTION!"); } }[/CODE] By looking at your code, this method actionPerformed will be called whenever the controls fire an action. I'm not sure if this is what you want. …

Member Avatar for kittie
0
253
Member Avatar for dmart

Here is the code you need. Read the comments to understand it. [CODE]public static void talk(String numbersAndLetters) { [B]//go through the string's characters[/B] for (int i = 0; i< numbersAndLetters.length(); i++) { [B]//get a char[/B] char currentChar = numbersAndLetters.charAt(i); [B]//switch on the char[/B] switch(currentChar) { [B]//if its 1 print one[/B] …

Member Avatar for freesoft_2000
0
150
Member Avatar for freesoft_2000

Maybe you should try setting the maximum heap size for the JVM. [CODE]java -Xmx256m MyClass[/CODE]You can put higher values if needed. For more help, [url]www.NeedProgrammingHelp.com[/url]

Member Avatar for freesoft_2000
0
366
Member Avatar for JavaFish

Replace the line [CODE]instructionPanel.add(instructionTextPanel);[/CODE]with[CODE]instructionPanel.add(slider);[/CODE] The scrollpane [I]slider[/I] was created to wrap the textpane. You must add that object to the panel not the original text pane. Are you sure you want this JTextPane to be disabled? For more help, [url]www.NeedProgrammingHelp.com[/url]

Member Avatar for JavaFish
0
2K
Member Avatar for nabil1983

Suppose you want to create an array of <type> with size 1555. <type> can stand for int, double, or String The syntax is: [CODE]<type>[] nameOfTheArray = new <type>[1555];[/CODE] This creates the 1555 empty slots. The actual contents depends on the type. For example: an int array always starts with all …

Member Avatar for NPH
0
101
Member Avatar for ramareddy_dotne

Web.config is a configuration file for an ASP.NET Web application. Windows applications use a similar file called Application.Config. The purpose of these configuration files is to set global settings like debugging information, authorization, etc. You can also define global values that can be accessed from .NET using the syntax: <add …

Member Avatar for NPH
0
114
Member Avatar for sydneyrustle

Display the value of a found item: 1. search for the item Item itemFound = null; for(int i =0; i < length;i++) { if( it.getName().equals(nameToFind) ) { itemFound = it; } } if(itemFound == null) System.out.println("Not found!"); else System.out.println( "Found it! Its price is: " + itemFound.getPrice() ); 2. Sell …

Member Avatar for NPH
0
147
Member Avatar for dummy00

Here is a way to do it. Suppose we have an array: int[] newBase = new int[100]; it will hold the bits for the decimal system the user inputs. Given 25 as decimal and 2 as base, do: 1. Compute ln(25)/ln(2) approx 4.64. Round it down to 4. 2. start …

Member Avatar for server_crash
0
229
Member Avatar for augie0216

Suppose the size listbox has Small, Medium, and Large Suppose the color listbox has White, Blue, White & Blue Then write: dim total as Double //check if its small and white If lstBoxSize.SelectedIndex = 0 And lstBoxColor.SelectedIndex = 0 then total = total + 5.99 End if //check if its …

Member Avatar for NPH
0
341
Member Avatar for bluesmiley

Everything looks good except for the sorting code: for(sort = 0; sort < 10; sort++) { for(unsort = 0; unsort < 10; unsort++) { if(input[unsort] > Largest) { Largest = input[unsort]; i = unsort; } } It seems to me that you are trying to use Selection Sort. Selection Sort …

Member Avatar for NPH
0
148
Member Avatar for nabil1983

To search the vector you would write String cdNameToFind = JOptionPane.showInputDialog(null, "Enter CD Name") ; CDEntry currentCD=null; for( int i = 0; i < cdVector.size(); i ++ ) { currentCD = (CDEntry)(cdVector.elementAt( i ) ); if( currentCD .getCdName().equals( cdNameToFind )) ) break; } if(currentCD == null) JOptionPane.showMessageDialog(null, "NOT FOUND!"); else …

Member Avatar for NPH
0
112
Member Avatar for moonduke

1. Its unnecessary to write: for (int i=0; i<128; i++) charSet[i] = 0; The int[] is already initialized with zeros. Unlike c++. 2. In the constructor, why do you do this code? The frequencies are already computed in charSet? for (int i=0; i<128; i++){ if (charSet[i] > 0) { frequency[count] …

Member Avatar for NPH
0
150

The End.