Why i cannot quit this while loop(java)?

I am new here and i got into trouble about my coding, i hope someone could help me break this loop, cause no matter what i type, it always in the loop.My code is as follow: boolean flag = true; while(flag) { System.out.println(“Please enter the movie’s title:”); title = s.nextLine().trim(); if(title.trim().equals(“”)) { System.out.println(“Please do not … Continue reading “Why i cannot quit this while loop(java)?”

Simple code snippet regarding arrays not returning expected value

Why does this code return 4 4 rather than 4 1? I traced the new values[k] to be 4 through the for-loop, but I understand that int[] numbers was copied to the original int[] values array, so did the int[] numbers change WITH int[] values through the for-loop? Is this a rule I’m not aware … Continue reading “Simple code snippet regarding arrays not returning expected value”

Why doesn't my program run correctly?

for my school project I have to create a program that outputs perfect numbers based on how many perfect numbers the user(teacher) want. The user can pick any number from 1-4 and it should display however many number the user chooses. Here is my current code. Please ignore the sumupTo, factorial, isprime, and the testGoldbach … Continue reading “Why doesn't my program run correctly?”

why does empty conditional statement for java for loop evaluate to true?

I apologize if this question has been asked somewhere in Empty for loop – for(;;) or else where on the site. I was wondering if any one knows why java would choose for their parser/compiler to evaluate an empty conditional statement in a for(;;){} loop as true instead of perhaps null or void ? as … Continue reading “why does empty conditional statement for java for loop evaluate to true?”

for-loop doesn't work in android try-catch block

I am making database of my school’s building and classroom with Realm. But, ‘for-loop’ in try-catch doesn’t work: public void startCheckRealm() { // Writing DataBase with Realm try { Log.d(“Realm”, “Init”); InitializeAPI.init_BuildingRoom(getActivity().getApplicationContext()); Log.d(“Realm”, “Complete”); } catch(Exception e) { e.printStackTrace(); } // Trying to check the Database whether it is right or wrong try { Log.d(“Realm … Continue reading “for-loop doesn't work in android try-catch block”

Check if all JComboBoxes have something selected any indexes (Other than index 0)

I have this code sample. JComboBox[] set = {jComboBox1, jComboBox2, jComboBox3}; for (int i = 0; i < set.length; i++) { JComboBox boxes = set[i]; int index = boxes.getSelectedIndex(); if (index == 0) { System.out.println(“Not every JcomboBox has something selected”); continue; } else { System.out.println(“Every combobox has selected something”); } I know every time the … Continue reading “Check if all JComboBoxes have something selected any indexes (Other than index 0)”

Java Multithreading | Finding all possibilities

I am trying to make a simple program that finds all the possibilities of getting a score with the available scoring methods in American Football. Here is my code that works and returns all the possiblities for the score for (int a = 0; (a * sf) <= score; a++) { for (int b = … Continue reading “Java Multithreading | Finding all possibilities”

Prompting a String value and check if it matches with a specific pattern. How can I solve it by using for loop and substring method?

I am doing an assignment which asks me check the given phone number whether it matches the pattern(the pattern is ddd-ddd-dddd) and the numbers are within 0 to 9. I want to use for loop and substring method, but I have no idea how to use them. This code is what I’ve done so far. … Continue reading “Prompting a String value and check if it matches with a specific pattern. How can I solve it by using for loop and substring method?”

Why does the loop print 0 at the end?

This is an example I found on a website. The result is really different from what I expected. But there is no further explain. int num = 0; for (int i = 0; i < 3; ++i) { num += num++; } System.out.println(num); Finally, the result will print 0. I am really confused about the … Continue reading “Why does the loop print 0 at the end?”

Java , put JsonObject into JsonArray, but JsonArray take the same value at the end of the for loop

I am a novice in Java, on this code I am trying to put JsonObect in a JsonArray , but the things is the JsonArray only takes the last value and it is duplicate in it. You do not need to understand all the code just the interesting part I have put the part Of … Continue reading “Java , put JsonObject into JsonArray, but JsonArray take the same value at the end of the for loop”