Print Route Method / Stuck In A Loop Of Printing Same Two Nodes

Nov 13, 2014

My issue is that when I run my search, it does find a goal. However, when I try and print the route using my print route method, it just gets stuck in a loop of printing the same two nodes. What is wrong with My A* implementation?

package search;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
 
[code]....

View Replies


ADVERTISEMENT

Print Statement Not Printing In Order To Call A Method From Another Class

Mar 17, 2015

I have wrote the necessary program for the class which was : Modify the customer class to include changeStreet(), changeState(), and changeZip methods. Modify the account class to include a changeAddress() method that has street city and zip parameters. Modify the Bank application to test the changeAddress method.

The problem arose when I went to test it. For some reason when it asks "Would you like to modify your account information? (y/n)" it will not allow the user to input anything and thus test the class. Here is my code

Class Customer
import java.util.*;
import java.io.*;
public class Customer {
private String firstName, lastName, street, city,state, zip;

[Code] ....

View Replies View Related

Loop That Calculate Distance Traveled - Why Java Not Printing Method Results

Apr 13, 2014

I am trying to write a loop that calculates the distance traveled (distance = speed * time). It should use the loop to calc how far the vehicle traveled for each hour of time. My program asks for hours and then mph but its not calculating time * speed. Here is my code.

public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
System.out.println("Enter Hours Traveled ");
int hoursTraveled = input.nextInt();
System.out.println("Enter MPH ");
int mph = input.nextInt();
 
[Code] .....

View Replies View Related

Printing Nodes Of Words That Does Not Exist In Dictionary

Jan 21, 2015

The task is

-getting words from dictionary text file and inserting them into a hash table - DONE
-getting words from a usertext file and inserting them into a red-black tree - STUCK
-after that i need to see if there is nodes of words that dosen't exist in the dictionary and print if so

kinda like a spelling checker

OK so the main code that hold the reading and storing part of dictionary and inserting to hash table

import java.io.FileReader;
import java.util.*;
import java.util.Arrays;
import java.io.File;
import java.io.BufferedReader;
import java.util.ArrayList;

[Code] .....

View Replies View Related

While Loop Stuck

Mar 16, 2014

I'm trying to do the following and my code is putting me in a loop and not allowing me to input a valid entry after using an invalid #.I ask the user for input which contains a loop if the user doesnt use the correct information, however the loop doesnt allow the user to input if the entry fails the which statement

import javax.swing.JOptionPane; // Needed for JOptionPane class
public class LoanQualifier
{
public static void main(String[] args)
{
double salary; // Annual salary
double yearsOnJob; // Years at current job
String input; // To hold string input

// Get the user's annual salary.
input = JOptionPane.showInputDialog("Enter your " +

[code]....

View Replies View Related

For Loop - Integers Stuck At 0

Oct 6, 2014

I have this code running correctly in Eclipse all except that it seems no matter where I declare, highest, lowest, average they always seem to stay at "0". I have a feeling the location of the Initialization is not the error since I have tried moving it to inside differ loops.

Stipulations on writing this code are:

Note: You do not need to use array to save each input score for this lab. A Single loop to read in each grade, compare with the current highest grade, lowest grade, and calculate the running sum at the same time.

import java.util.Scanner;

/*Write a program that prompts the user to enter the total number of students first.
*Then ask the user to input each student’s grade and use loop statements to read in each grade.
*Check input grade to make sure 0<=grade<=100, if the user input any other number, print out warning message and ask the user to input a new grade. Display the highest score, the lowest score and the average.
*/

public class LoopStatements {
// Main Method
public static void main(String[] args) {
// Initialize
int grade = 0; // grade value

[Code] ....

View Replies View Related

Stuck In A Loop - Max Value Gets Reset To The Next Value In File

Mar 14, 2014

The problem i believe is that I have the max value set to the first value given out, but every time the loop repeats the Max value gets reset to the next value in the file.

Essentially the program is supposed to read a list of credit card transactions and tell the user which transaction is the highest.

Here's the list of the sample file, note that the number of transactions could change that's why i haven't tried simply passing the values to method.

Bicycle 562.90
Groceries 138.43
Hotel 612.00

import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class CreditCards {
public static void main(String[] args) throws IOException {
String fileName = "C:/Users/David/Desktop/CreditCard.txt";
File inputFile = new File(fileName);

[Code] ....

View Replies View Related

Threads Stuck On Closing Brace Of While Loop

Apr 14, 2014

While analyzing the thread dumps for a performance issue in our java ee web application, I see many thread dumps stuck on a closing brace of a while loop. Here is the code block of a third party library bitronix (version 1.3.3 SNAPSHOT)
 
public XAResourceHolderState findXAResourceHolderState(XAResource xaResource) throws BitronixSystemException {
        Iterator it = resources.iterator();
        while (it.hasNext()) {
            XAResourceHolderState xaResourceHolderState = (XAResourceHolderState) it.next();
            if (xaResourceHolderState.getXAResource() == xaResource)
                return xaResourceHolderState;
        }      
        return null;
    }

The thread dumps indicate that many threads are stuck in RUNNABLE state on line number 07. What could be the possible reasons on why a thread could get stuck on a closing brace of a while loop? The iterator of the while loop is a custom implementation.

View Replies View Related

Stuck On Adding Entries Method

Apr 13, 2014

I think I'm about 90% complete with this program but I'm stuck on my adding entries method. It gives me a runtime error which says:

Enter the name:
Bill
Exception in thread "main" java.lang.NullPointerException
at Phonebook.addEntry(Phonebook.java:70)
at Phonebook.main(Phonebook.java:49)

Here is my code:
/*
* This program asks the user for input for a name, phone number and notes up
* to 200 entries. It stores every contact in a file. Type 'h' for help while
* running this program.
*/
import java.util.Scanner;
import java.io.*;

[code]....

View Replies View Related

Stuck On IsBorrowed Method Implementation

Jul 19, 2014

Basically I have a class called Book. Its supposed to have a few simple methods that set the title of the book, mark it as returned or borrowed. So specifically my problem lies in the implementation of the method that decides if the book isBorrowed. I was thinking i'd use a simple if/else statement but the way i've been trying hasn't been successful. This is what i've tried so far.

public class Book {
String title;
boolean borrowed;
boolean returned;
boolean isBorrowed;
// Creates a new Book
public Book(String bookTitle) {

[Code] .....

View Replies View Related

Unable To Print A Loop Inside Array Of Greater Size Than Loop Itself

Jan 27, 2015

I am trying to print a loop inside an array of a greater size than the loop itself. Like for example I have an array of size 7 but it has only 3 elements.

int[] array=new int[7]
array[0]=2;
array[1]=3;
array[2]=4;

now what I want to do is print these three numbers in a loop so that my array[3]=2;array[4]=3;array[5]=4 ...... till the last one. Also the array could be any size and not just 7.

View Replies View Related

JOptionPane Printing From A For Loop?

Feb 13, 2015

I am writing a program that has to do with ciphers and cipher shifts. The program itself works fine, but I am having trouble printing out the answers to JOptionPane. I know the basics of JOptionPane, but my problem is this:

Majority of my program takes place in a for loop, and resolves the cipher (it is a basic cipher program) 1 digit at a time. So, only the last DIGIT (I don't know how to convert a digit to a CHAR in JOptionPane) is printed to JOptionPane. Here is my code:

public static void main(String[] args) {
String cipher = JOptionPane.showInputDialog(null,
"Please enter a sentence or word that you wish to encode or decode. This program uses " + " a basic cipher shift.");
int answer = 0;
String upperCase = cipher.toUpperCase();
char[] cipherArray = cipher.toCharArray();

[Code] .......

View Replies View Related

Algorithm To Find Shortest Route Between Two Points In 2D Grid Array

Mar 24, 2014

What would be a good and simple algorithm to find the shortest route between two points in a 2D array[grid] ? There can be certain obstacles in the grid i.e. some of the cells may be inaccessible. I tried googling for it and found that A* is the best for this but I am just a beginner and would like to start with something much simpler.

View Replies View Related

Nested For Loop - Pattern Printing

Feb 13, 2014

I don't know how to write a program based on for loop like pattern printing.etc

View Replies View Related

Printing Each Value In Multidimensional Array Using For Loop

Dec 5, 2014

I want to print each value in the multi-dimensional array using a for loop but there is a problem.

Here is the script:

Java Code:

public class LearningJava
{
public static void main(String[] args) {
int[][] Grid = {
{12, 24, 36, 48, 60},
{1, 3, 5},
[Code] ....

Printing i: 0, x: 12
Printing i: 0, x: 24

Exception in thread "main" Printing i: 0, x: 36

Printing i: 0, x: 48
Printing i: 0, x: 60

java.lang.ArrayIndexOutOfBoundsException: 5
at LearningJava.main(LearningJava.java:11)

It's suppose to get the length of each array and print all the values in that array and then move to the next one.

I tried adding .length

Java Code: for(int x = 0; x < Grid[i][x].length; x++) mh_sh_highlight_all('java');

but then it doesn't work at all.

View Replies View Related

Printing Pattern Using Nested Loop

Jan 19, 2015

I built a java code to print the following pattern using nested loop:

1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 6 5 4 3 2 1
1 2 3 4 5 6 5 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1

And here is my code

public static void main(String[] args) {
for(int i=1; i<=8;i++)
{
for(int k=1;k<=i;k++)
{
System.out.print(" ");

[Code] .....

which gives the partially true output:

123456781
123456721
123456321
123454321
123454321
123654321
127654321
187654321

I couldn't figure out how to place the spaces.I have made some changes on the code, but it didn't work.

View Replies View Related

Building Linked List Whose Nodes Data Is The Sum Of Nodes Of Other List

May 1, 2014

public void add(int d){
listNode l = new listNode (d, null);
l.next = first;
first= l;

public list Sum2List (list l1, list l2){
//variables
int sum;

[Code] .....

But I have a problem in my first listNode where it ll be pointing to null, thus in the sum2List method the program checks the while condition into false and doesn't go through the loop.

View Replies View Related

Why Thread Loop Is Not Finishing Without Mentioning Printing

Jan 13, 2015

I was trying to read an article from here : [URL] ..... I was doing the same example but loop is not ending. Thread is struck at CalculateThreadDemo run method. If i mentioned System.out.println then it got terminated else infinite loop continues. I don't understand this.

code:

BlockedThreadDemo
public class BlockedThreadDemo extends Thread {
private boolean isFinished = false;
BlockedThreadDemo(String name) {
super(name);

[Code] ....

Without commenting the statement:

597222
597223
597224
597225
isFinished: true
main thread is dead
597226
CalculateThread is finished.

i: = 49i: = 13i: = 10
BlockedThreadDemo is finished.

View Replies View Related

Using While Loop For Printing User Entered Name From Console

Jul 2, 2014

Ask user to enter a name alphabet by alphabet, and print d whole word as output,,,,,, use while loop?Since i am new to JAVA..i have no clue on how to begin?

View Replies View Related

Loop That Stops Printing A File And Adding To Stack

May 6, 2015

I'm supposed to add characters to a stack and pop them once the adjacent delimiter is read in from a text file. Moreover, program is supposed to print out the incoming text from the file, but stop when the applicable delimiter is not on top of the stack. As in, a '[' doesn't have a ']'.

I've got the program so it can pop and add to the stack correctly, and stops adding at the correct time, but I cant seem to get it to stop printing. I know a switch statement method in another class seems obvious, but I was trying to practice nested loops.

This is the main program:

import java.io.*;
import java.util.Scanner;
import java.io.IOException;
import java.util.Stack;
public class DelimiterChecker {
public static void main(String [] args) throws IOException {

[Code] ......

Moreover, the file I'm reading for is simply:

{
System.out.println(1)
System.out.println(2)
System.out.println(6 <-------------missing delimiter
System.out.println(7)
}

View Replies View Related

How To Print Big Integer Using For Loop

Mar 6, 2015

I amtrying to iterate a value of L,R both are range of BigInteger but its not working

BigInteger L=in.nextBigInteger();
BigInteger R=in.nextBigInteger();
for (BigInteger bi =L;
bi<=bi.compareTo(R);
bi = bi.add(BigInteger.ONE)) {

//Task to do with Numbers
}

I am trying to iterate a for loop in range of L and R but its not working

View Replies View Related

Print A Diamond Using For-loop?

Mar 26, 2014

I am currently trying to print a Diamond using for-loops but I seem to be confusing my self / over-complicating it.

This is what I have so far [URL]). When I run the code I get [URL].

I want to duplicate it on to the other side but I can't seem to be able to figure out a working for-loop to print it out.

Also, is there a faster/efficient method of doing something like this?

View Replies View Related

While Loop To Print All Odd Numbers Between 1 And 100

Apr 3, 2015

I want to write a while loop to print all odd numbers between 1 and 100.

But it gives error. Where is the mistake?
 
public class pro {
public static void main(String[] args) {
// TODO Auto-generated method stub 
int c;
int x=1;
 
[Code] ....

View Replies View Related

Symbol Won't Print From For Loop

Oct 20, 2014

On line 45 i am trying to add "-" symbol to my output phone number. As of now the out prints like "1800*45*3569377. I want it to print 1800-3569377, or even more ideal: 1-800-356-9377. When printing normally (system.out.println) I can print symbols, but when I try to print from a for-loop it says "unclosed character literal." import java.util.Scanner;

public class Phone_010473030 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a phone number string: ");
String Phone_num = input.nextLine();
Phone_num = Phone_num.toUpperCase();

[code]....

View Replies View Related

Print Variable Which Only Exists Within For Loop?

Jul 18, 2014

There's loads of problems with this. What I'm trying to do.

1) get a program to add the contents of an array together, preferably with a for loop and not the heavy handed version I've tried to use here.

2) get the for loop's output just once, since it won't compile or recognise the variable outside of the loop. How do I make the loop's 'counter' variable available everywhere?

public class retint {
 public static void main(String[] args){
int[] onetoTen = {1,2,3,4,5,6,7,8,9,10};
for (int i=0; i<10; i++) {
int counter = (onetoTen[0] + onetoTen[1] + onetoTen[2] + onetoTen[3] + onetoTen[4] + onetoTen[5] +
onetoTen[6] + onetoTen[7] + onetoTen[8] + onetoTen[9]);
 System.out.println(counter); 
}
}

Terrible code, I know. There has to be a more efficient way.

View Replies View Related

Print Triangle - Loop Is Not Working

Jul 7, 2014

I am trying to make a program that prints triangle... and I did various test on each method to realise that the problem lies with this segment.When I call this method, nothing prints out, I figure there is something with the loop that I am not realizing.the loop is backwards because it's supposed to have the right side edge parralel (when I try to print it out the spaces do not appear, imagine the x are space...), so as each line is looped the # of spaces diminishes

xxxx*
xxx*x*
xx*xx*
x*xxx*
*****

public class test {
public static void main(String[] args){  
for (int countdown = 5; countdown <= 1; countdown = countdown--){
showNTimes(countdown, ' ');
showNTimes(5- countdown, '*');
System.out.println("");
}
}
public static void showNTimes ( int nbTimes, char carac ) {
for ( int i = 1 ; i <= nbTimes ; i = i + 1 ) {
System.out.print( carac );
}
}
}

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved