Tagged Questions
-1
votes
2answers
56 views
Need some guidance with while expression [closed]
So, I've been coding this hangman program and at the beginning, I want the user to have to type "start" for the program to begin. So, here's what I have so far:
package hangman;
import ...
-1
votes
3answers
42 views
Using a while loop to call a method based on the argument received?
I'm having trouble logically trying to figure out how I would do this. I might be going at it at the completely wrong approach. This example I will provide is what I would LIKE to have, but I know ...
-2
votes
6answers
59 views
Exit a while loop Java [closed]
I can not get this loop to stop even though I set the count variable = to false. And it won't go to the next method called in the Main class. Any help would be greatly appreciated.
Main Class
public ...
-1
votes
2answers
19 views
Asking User Multiple Times for Input in Java
So far I have this:
package CashRegister;
import java.util.Scanner;
public class CashRegister {
public static void main(String[] args) {
Scanner askPrice = new Scanner(System.in);
...
0
votes
2answers
32 views
Adding database column to JComboBox
I've searched around for the answer to this, but to no avail. When I compile this, it just returns the last row of my table in the database and not a list of the entire column as I expect. I believe ...
-6
votes
4answers
62 views
Java while 2 conditions
I need to have something like this, but now sure if possible:
a while with 2 conditions and when first condition is false I do not want the second condition to be considered, so I want the while to ...
-8
votes
3answers
40 views
How to rewrite ArrayList in opposite direction [duplicate]
I have a ArrayList and I need to rewrite it in the opposite direction. How to do it?
List<Posts> viewList = new ArrayList<Posts>();
viewList = viewLogic.getPostsList(username);
0
votes
1answer
55 views
Leibnitz Method for Pi Program
I am making a program to prove Leibnitz method for computing PI.
(pi/4) = 1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + ...
I took a very interesting approach to this and I am just wondering if there is a much ...
1
vote
1answer
76 views
For loop isn't printing correct “.”
What I am trying to do is have it take a java file that look like this
public class test1 {
public static void main ( string[] args ) {
System.out.println( "This is Test 1." );
}
}
And it is ...
0
votes
3answers
61 views
check empty edit text in an alert dialog android
I have the following code for checking empty edit text in an alert dialog, but it is not working
if (mPhoneNumber == null) {
mPhoneNumber = GetNumber();
if (mPhoneNumber == ...
-2
votes
3answers
41 views
Access a variable from inside a do while loop
How can I access a variable from inside a do while loop in Java?
This is the exercice i'm currenty working on ...
We ask the user write a value until the value entered is not is between 0 and 10
...
1
vote
2answers
43 views
Error while statements
I'm trying to make a statement that when you enter an integer terminates. I can only make one that continues with an integer. I was also considering trying to catch the specific error witch is the ...
0
votes
0answers
44 views
Loop neither looping nor breaking while reading from a file
I have been having a strange issue. My loop suddenly ceases to loop and will also not break. It reads fine for the first several items and just suddenly stops.
I have the following loop to read from ...
-1
votes
3answers
54 views
Infinite loop stuck [closed]
I have been looking at this for a bit.. and I even put in the item = null to see what happens.. but this bit of code keeps getting stuck in an infinite loop. item is always equal to null and should ...
13
votes
2answers
130 views
While(false) causes unreachable statement compilation error
I was recently removing a block of code from our code base before a release and used an if(false) statement to prevent execution:
if (false) {
ArrayList<String> list = new ...
3
votes
2answers
98 views
In what situations can do-while be more efficient than while?
While vs. do-while
While and do-while are functionally equivalent when the blocks are empty, although while seems more natural:
do {} while (keepLooping());
while (keepLooping()) {}
One typical ...
1
vote
2answers
54 views
While Loop issue (Java)
I'm trying to make a while loop that prompts the user to re-enter data if they use an invalid entry. In my program I'm asking the user to input a number(0-3), so if they enter anything other than that ...
-6
votes
0answers
65 views
Get out of while loop [closed]
i need some help with this code. i cannot seem to figure out how to make it work completely.
this is basically what i have to do
You are to write the code for the method getBigOddValue where the ...
0
votes
4answers
41 views
Trouble with while-loop statement
I keep getting errors when I try to compile these codes below, I'm currently using JCreator.
import java.io.*;
public class Number //class name here, same as file name
{
public Number()throws ...
0
votes
3answers
51 views
While loop makes applet white screen and unresponsive
Here is my loop code (This is the only code relating to my loop):
while(true)
{
try {
Thread.sleep(20);
System.out.println("1");
} catch ...
2
votes
2answers
58 views
Java specific game - move while jumping
I need to be able to move my character while he's jumping. I'm making a new post because my issue is specific to the game I want to develop.
The thing is that I don't want the character to move in a ...
0
votes
1answer
15 views
Control Statements: Why is my 'New Balance' change when I 'charge to credit' then 'pay credit' twice?
I tried reading from the start of this Java book and do some of its exercises for summer vacation. The I came up with this problem:
"(Credit Limit Calculator) Develop a Java application that ...
1
vote
3answers
62 views
Why does this code become an infinite loop?
I wrote this simple code to fetch a double and just keep asking until one was given, but when you give a string it just turns into an infinite loop and I can't figure out why. Any reason why it ...
0
votes
3answers
53 views
How to rewrite empty while block
I have instantiated a BufferedReader to read an input stream. It has a boolean ready() method that returns false until the reader can be read. Now I have
BufferedReader br = new BufferedReader(new ...
1
vote
2answers
79 views
How to break from a loop after the condition is met
Hi I have been trying for the past hour to break from this loop and continue since already met my condition once. My application pretty much reads a serie of lines and analyzes it and then prints the ...
-1
votes
1answer
57 views
Teacher insists to use if statement instead of while statement, while with while statement my code works
I'm having a little problem here.
We been told to program some simple things but I can't run the code perfectly with if statement.
With while statements, my code works perfectly but teacher insists ...
0
votes
4answers
57 views
Small program having some looping issues
Just having a small issue with a small program that i'm doing for my entry level programming course.
This loop is infinitely repeating and I can't seem to figure out why. I'm suspecting that the ...
1
vote
3answers
32 views
accessing while loop variable
I am using a scanner to retrieve from a textfile. When I try to access my info1 from outside of the while loop, it says variable info1 might not have been initialized but I have already initialised it ...
1
vote
2answers
48 views
ArrayList keeps resetting after loop. what am I doing wrong?
Everytime I loop through the arrayList, it resets itself. Eventually the goal is to make a program that finds the mean of numbers in an arrayList
public class loops {
public static void ...
-2
votes
3answers
81 views
While loop won't stop looping Java
I have created simple table called Reservations and this table have following columns: ID, DUE_DATE, PRODUCTS_PAID, RESERVATION_NAME, SALE, TOTAL_SELL_PRICE and CUSTOMER_ID.
Now what I want to do is ...