1
vote
4answers
58 views

Runtime Ignoring While Loops?

I am new to the forums so first of all I'd like to say "Hi"! I'm new to Java programming and am trying to make a simple payroll calculating program with three while loops. The first while loop keeps ...
2
votes
4answers
75 views

Can someone Explain Why This While Statement Has to be AND

So basically I am having some trouble understanding the logic that is not allowing this statement to use "OR" but to work perfectly using "AND". By my logic saying equals Y or y or N or n, should ...
-1
votes
1answer
22 views

Using a while loop to take in a string of numbers and then returning the average

Hello I am writing a program that wants me to take in a user input and return the average of the input the user has to enter (0) to stop the program. My issues come in the incriminating the user ...
0
votes
0answers
28 views

How to use a if statement in a while loop in java? [duplicate]

I have a binary string (010101011101010001) and i want to have a if statement that checks the first character and executes a command like printing "this is a 1" is the character is a one. The code I ...
-1
votes
0answers
40 views

While Loops in Java [duplicate]

I'm working on this program that is supposed to ask a user to enter either an uppercase or lowercase y and then prompt them to enter a phone number. This is supposed to repeat until they enter ...
-2
votes
1answer
47 views

Count how many time a loop has ran [closed]

I need to count how many times the while loop runs. When I run the code the intCount=0 which is not the right answer. How do I get it to spit out the right value. I did exactly what my teacher said to ...
-1
votes
2answers
44 views

Scope of Variables in a While Loop

int i = 1; while(i == 1) { if (answerHold.equals(generate)) { qgCharacter(); i++; } else if (answerHold.equals(create)) { ...
0
votes
4answers
68 views

While-loop termination

If I comment out the line garbage = scan.nextLine();, the while-loop runs infinitely. Otherwise, it does not. I understand why it will run infinitely if there were only the print command, but I don't ...
-1
votes
0answers
68 views

Java source code: infinite loop

I understand this is long but it took me a while to come up with this class that converts infix expressions to post fix however when I execute it in main, I get in an infinite loop: import java.io.*; ...
0
votes
3answers
73 views

how to enter an infinite loop until valid data is input?

The loop should "stay" on the same record until a valid State is entered. The valid options are logged as a warning: [undefined, x, o, c, a, l, d] but, apparently, the loop just continues on to the ...
57
votes
4answers
4k views

Do “nothing” while “condition”

While browsing the code for the Java 8 version of ForkJoinPool(which has a few interesting changes from Java 7) I ran across this construct (here): do {} while (!blocker.isReleasable() && ...
-2
votes
1answer
27 views

Check, if String contains only needed characters. If no - input new String from Scanner [closed]

User inputs a string in the console. Scanner sc = new Scanner sc.nextLine(); This String should contain only symbols A,B,C,D,F (it is possible to be something like this: AAABCCDDD If string ...
-6
votes
0answers
34 views

Slot machines that hit at predetermined times. ex: slotMachineOne plays 30 quarters every 35th time it's played. [closed]

Margerie takes a jar of quarters to the casino with the intention to win big. She plays three slot machines in sequence. Each play costs one quarter. The following are constants:The first ...
-1
votes
1answer
56 views

Understanding auto decrement in Java

I am new to Java. I'm trying to run while loop and if condition inside while loop. There is decrement in the middle of while loop. Can I put the decrement (x=x-1) at the end? What does it mean if i ...
0
votes
4answers
25 views

Scanner Object giving me error in While loop

I am having a small issue with getting this program to run properly. /** * * @author Randy */ import java.util.Scanner;//Import scanner public class RandyGilmanhw2a { int year_of_birth; ...
0
votes
2answers
28 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
69 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 ...
-1
votes
2answers
39 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
50 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 ...
2
votes
5answers
77 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
31 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
49 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
48 views

Why does this method repeats its loop? [on hold]

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
68 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
36 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 ...
32
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
57 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
49 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
33 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
44 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
53 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
72 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
36 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
29 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
98 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 ...