0
votes
2answers
27 views

how to update another operation with the values obtained from the result set using while loop?

Here is my java code: public int function(String name) { int i=0; int id=0; try { String get_id="SELECT id FROM table_name JOIN tbl_2 ON tbl_name.pk_id = tbl_2.fk_name_id ...
0
votes
1answer
57 views

iterating lines with loop in java

First of all I must say I read all the previous answers related to this topic and none of them were able to help me with the issue I am experiencing right now. I created a method which reads all the ...
0
votes
2answers
35 views

Java do while loop back to the beginning of application

This question is a follow-up from this link Java SE do while loop issues This is an application asking for a room's name then second prompt to ask for its dimensions to perform some calculations. ...
0
votes
2answers
47 views

Java SE do while loop issues

I have a problem with my java application when i compile my codes it says that it cannot find symbol roomLength. what the application supposed to do is prompt the user to input a room name then if it ...
-3
votes
3answers
69 views

sum using while loop in java [on hold]

Can anyone help me? I'm confused. My teacher gave me homework which is to implement addition (sum) using while loop in java. Additionally, when you press 1 at runtime it should end the program. ...
2
votes
5answers
73 views

Basic Java: While loop for basic quiz?

I started learning Java last night, and I'm trying to make my first code without it being dictated to me! It is a simple quiz question that asks the user "Do you think my dog is cute?" If they answer ...
0
votes
0answers
21 views

Checking user input for integer with a while loop [duplicate]

I am new to java. I am creating this program that will calculate your weight on planets of our solar system. I am currently have part of it finished, but I am caught up on checking the users input for ...
-4
votes
1answer
30 views

How to retrieve values stored in hashmap

I have a hashmap of Task I want and i added the tasks below to the hashmap I want to retrieve all the task that I in the hashamap I called the method getAllTasks() I dont know what I am doing wrong ...
0
votes
3answers
48 views

Using a nested if and else if statement inside of a while statement

I've been having issues getting my program to do what I need it to do. There are no syntax errors in the code. Firstly I've got my program set to ask the user for a first and last name for a maximum ...
-2
votes
2answers
43 views

Why does this method repeats its loop?

This method retrieves and validates a social security number from the user. It works fine if the input is valid. If not, while (true) repeats instead of going to the else { ...
0
votes
1answer
41 views

If statement is unexpectedly running. How do I debug this? [duplicate]

The purpose of this application is to get the full name of a user, and split them up. The results are printed. if(nameParts.length < 2|| nameParts.length > 3) is somehow gaining control from ...
0
votes
4answers
65 views

i wanted to know what exactly happens in the following java code for printing a triangle :

code 1 : I have declared int b = 0 outside the first while loop: public class apples { public static void main(String args[]){ int a = 1; int b = 0; while (a < 5){ ...
2
votes
3answers
73 views

How to show the values in the LOOP for every 10 second in java

I have a while loop where in it constructs a JAVA String by appending the output from a shell script. System.out.println("Here is the standard output of the command:\n"); while ((s = ...
0
votes
1answer
35 views

multithreaded server, loop is working only once

I have problem with my multhreaded server for bridge auction. The topic of it is less important, all I need to do so far is to make the loop inside the run method work for more than only one "lap". I ...
-2
votes
5answers
69 views

Iterating through String

Input preBody = The AThe CThe IThe O{ I am trying to get the output as The A The C The I The O and ignore a value less than 5(bodyCnt)[ { ] So far What I did is. int bodyCnt = 5 int cnt = 0; ...
-1
votes
1answer
117 views

Is this valid to do? (c, c++, java) [closed]

void loop() { if (button || tilt) { do { while (ss.available()>0) { char c = byte(ss.read()); if (gps.encode(c)) ...
0
votes
2answers
26 views

Reading text files, for in while vs while in for (java)

This is a very easy code sample of an exercise for school. I got it to work, but I don't understand why my first idea didn't work. My first idea was the while loop in the double for loop (see comments ...
31
votes
4answers
1k views

while(true); loop throws Unreachable code when isn't in a void

I was doing some small programs in java. I know that if I write while(true); the program will freeze in this loop. If the code is like that: Test 1: public class While { public static void ...
-1
votes
4answers
56 views

Java endless Scanner loop

Im trying to print the same strings as the user are pasting into the console. My code looks like this: import java.util.Scanner; public class reader { public static void main(String[ ] args) ...
1
vote
3answers
50 views

Trouble with my conditions statement

I am trying to make a condition where the user is checked by three numbers. I cannot seem to figure this out, I want to make sure the user only chooses one of these 3 numbers. System.out.println("How ...
0
votes
2answers
45 views

Compare word to Text file Java

we are supposed to create a program that reads a word from a JTextField and compare it to a list, then we have to count how many lines to the word if it exist and display the same line from another ...
-2
votes
2answers
26 views

counter in while loop does not increase

i still new to java language. i need to develop a scholarship application in java. i need to print the successful application in output.but, why counter in this code does not increase if i enter for ...
0
votes
1answer
41 views

How to break from a while cycle, that is used to receive data from a socket, when the timer ends? [duplicate]

I have a client that receive cyclically data form a server while (true) { System.out.println(in.readLine()); } I want to set a timer of 5 sec to exit from the loop when the time is expired. I ...
0
votes
3answers
56 views

Why does it prompt me twice in a row?

This while loop that is suppose to prompt for a price and a y/n and end if price = 0. However, when I run the code, it asks for the price, takes it, goes to a blank line, and I have to enter the ...
0
votes
2answers
31 views

Need logical solution for uncountable loop dillema

Supposed I have this kind of loop in java (not an exact code, neither it's a truly valid code, but just to give you a general perspective of situation): print "<ul>"; while (res = ...
0
votes
1answer
43 views

while loop android class not found

So I am trying to create a simple loop in android but my varialbe is not recognized? Here is the problem code package com.whatwouldayogido.iching3.app; import java.util.Random; public class rollHex ...
-2
votes
1answer
52 views

trying to get a positive integer output from a while loop with console.hasNextInt

Scanner console = new Scanner(System.in); System.out.print("type your age: "); while(!console.hasNextInt()|| console.nextInt() <= 0){ System.out.print("enter a valid age: "); ...
0
votes
1answer
65 views

while loop do not loop

Hi i am practicing java and just learning java for few days. i need to subtract the scholarship amount of 500000 by 100000 but i seemed to be stuck on 400000 and it does not continue. What is wrong ...
0
votes
5answers
53 views

Code not working while lopp with &&

I don't understand why my code does not work see below I am supposed to transform this code public class Iteration { public static void main(String[] args) { int x, y, z, sum, tal; ...
0
votes
3answers
35 views

menu in a while loop

I want to make a kind of menu inside a while loop. I wrote this code System.out.println("age , sex or exit" ); BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in)); ...
0
votes
0answers
28 views

OpenCL while loop

im developping a ray tracer, im at the optimization pass and i need to search nodes in a tree and here the problem: I have a while loop with a 'gg' variable that is a security to prevent kernel crash ...
2
votes
3answers
83 views

While loop with no purpose?

While working through a Java tutorial book, I came across this piece of code: while(getImage().getWidth(frame) <= 0); I at first thought this was a typo, but it is repeated several times ...
-2
votes
3answers
62 views

Having trouble deciding where to put a while loop in my pig dice game program

So I'm writing a program where two users take turns rolling a die. If the user rolls a 1 then their turn ends, if the user rolls 2-6 then I'm supposed to keep a running total of the points scored ...
-3
votes
1answer
37 views

saving a veriable in a while loop for later use

I cannot seem to find the answer anywere, albiet the fact that i am very new to java and are probably looking for the wrong thing. public class ClassMethodtest { /** * @param args the ...
0
votes
2answers
30 views

Exception not being created or displayed

I'm doing an assignment where I have to create a schedule and handle certain exceptions for bad input. I have it working mostly but for my generic exception throw it doesn't seem to be creating the ...
1
vote
3answers
96 views

Endless java loop while taking an input

I have this problem with a while loop here: while((input = InputHandler.getInt()) != 1 && input != 2){ if(input == InputHandler.CODE_ERROR) System.out.print("Input must be ...
-3
votes
2answers
61 views

Incorrect Loop in Java Program [closed]

I've hit a brick wall with a Java project that I've been working on casually over the past several weeks. The majority of the code works properly, however, the loops in my program are creating an ...
-1
votes
1answer
61 views

While loop behaving unexpectedly in Java

I'm trying to get my loop to go over and over again until the user types in "quit" then it will quit. Basically I'm trying to get my Finch robot to change nose color depending on how it's positioned, ...
0
votes
0answers
28 views

How to make hasNextInt() take the entire line [duplicate]

For a simple test of hasNextInt(), the program asks for an integer and if it is not an integer, it asks for input again. import java.util.Scanner; public class hasNextIntDemo { public static ...
-1
votes
1answer
30 views

loop to fill 2d array produces outofboundsexception on last char [closed]

I am trying to fill a 9x9 array via input from the user: Field field = new Field(); int col = 1; int row = 1; do { char ch = In.readChar(); if (ch == '-' || ch == '0') { col++; } ...
2
votes
1answer
94 views

What is the correct way to implement this do while?

I start my GUI like this, which seems correct. javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JFrame gui = new JFrame(); ...
0
votes
0answers
47 views

My while loop works twice and then stops working

This is a tic tac toe program, and the part you are seeing is the user and the computer decisions. I have a while loop for both and when I run it the user goes and the computer responds twice and then ...
0
votes
1answer
19 views

How do I use JOptionPane in a while loop?

The code segment below is a part of a bigger program, but I think this is where I'm having the issue. So, I am trying to use a while loop to ask for input over and over until the program is done, and ...
0
votes
0answers
41 views

retrieving values in a result set using while loop

I have this method (attendanceView()) that retrieves values from a database. I was able to retrieve the number of rows and columns the result set have. but when I use "while(rs.next())", the result ...
-1
votes
2answers
31 views

endless while loop in Java

int option=0; while (option1!=1 || option1!=2){ System.out.println("Give 1 for the first list which includes what we have in our exhibition"); System.out.print("and 2 which ...
2
votes
1answer
34 views

Receiving PDUs that are sent over a network, and filtering them as received before displaying to user

I have the following Java method, which I am trying to use to filter PDU messages that are received over a network, and display only the PDUs which match the filter criteria to the user: public ...
0
votes
3answers
56 views

program laggin once it reads about 30,000 zipcodes

My program is to match the Craigslist US sites and assign zipcode to it from a US zipcode file. First it reads the zipcode file which has US zipcodes and appropriate cities. After reading each entry ...
1
vote
3answers
98 views

How to break a while loop from an if condition inside the while loop?

I want to break a while loop of the format below which has an if statement. If that if statement is true, the while loop also must break. Any help would be appreciated. while(something.hasnext()) { ...
0
votes
2answers
44 views

While Loop is skipping Satements

The purpose of this was to ensure that the user does not receive any mismatch errors. Every time they enter a String by accident, I want the program to say "Sorry, please choose exercises from above" ...
-3
votes
1answer
31 views

Inserting into array from file

Here is my code: while (scan.hasNext()) { if(scan.next().toLowerCase().equals("car") ) { carsdata[count++] = new Car(scan.next(), scan.nextInt(), scan.nextInt(), ...