loop « string « Java Data Type Q&A





1. What is the error in this string loop?    stackoverflow.com

for (int i = len-2; index>= 0; index --)

2. Java clearing the string buffer after loop    stackoverflow.com

How do you clear the string buffer in Java after a loop so the next iteration uses a clear string buffer?

3. unexpected behavior in printing string in loop    stackoverflow.com

I don't understand why this is happening: I have an integer being passed to a label object:

int NTURNS = 3;     
for (int i = NTURNS; i > 0; ...

4. help with making a password checker in java    stackoverflow.com

I am trying to make a program in Java that checks for three specific inputs. It has to have pass these tests:

  1. At least 7 characters.
  2. Contain both upper and lower case alphabetic ...

5. Can StringTemplate iterate through 'values' in a String?    stackoverflow.com

I have a String made up of several Strings seperated by commas. Using StringTemplate, is there an easy way to write a seperate line for each 'value' in this outer ...

6. Java: how to create 10 cats? when Cat ("cat" + i) = "cat name" not working as in other languages    stackoverflow.com

using loop, I can create

My cat is: Cat1
...
My cat is: Cat1
However, when I tried to use
  Cat ("cat"+i) = new Cat("Cat" + i);
I'm making mistakes.... So, what is the simplist way ...

7. java input string and stop when 'stop' is entered    stackoverflow.com

this is my code and I have a do-while loop which should carry on unless the string "text" entered is "stop". However when I compile the code it doesnt stop and ...

8. Java for( x : y) execution    stackoverflow.com

I have the following for loop:

for(String s : someString.split("\\s+")){
   //do something
}
Does java execute the split() method each time the loop iterates, or does it do it only once and ...

9. Adding strings to lists - Java    stackoverflow.com

        String t1 = request.getParameter("t1");
        String t2 = request.getParameter("t2");

        List<String> ...





10. How do I use a while loop and print an addition function in Java Method?    stackoverflow.com

I am having an issue in the last println. I want it to print the number of times the previous string was printed and add all the numbers together. So if ...

11. Can I make the name of a string change each time a loop repeats?    stackoverflow.com

Basically I need a different string created each time a loop repeats. I need a new string each time the loop repeats so I can store a whole bunch of different ...

12. How Do I Create a Loop in Java and Increment an Index to Use As Part of a String?    stackoverflow.com

So for my current program, I am currently doing this: Java Code

        ArrayList<Section> aMainSection = new ArrayList<Section>();
        Section ...

13. Java: String padding, String manipulation without loop    stackoverflow.com

Possible Duplicate:
Padding Strings in Java
I had to write a method today that took a string and padded it with 'n' number of 0s
private String ...

14. Java String search without a loop or if statement?    stackoverflow.com

If I have a

String myName = "First Last";
How can I, without an if or any other conditionals/loops, return just the initials of the name?? I've been looking forever on this! Thanks

15. Check if string is following ISBN-13 in Java    stackoverflow.com

Im trying to check if a string (important that it is a string) that im reading is correct accoring to the rules of ISBN-13. I found a formula For ...

16. Finding index of a string in a loop    stackoverflow.com

I'm trying to create a program that will return a certain number decomposed to powers of two. For example 45 would be shown as "2^5 + 2^3 + 2^2 + 2^0", ...





17. Java Looping string replacemnet    stackoverflow.com

I want this part of my code for my calculator and since I am replacing x with the variable I need to made sure something like 2x is 2*x. Why is ...

18. Loop doesn't assign string the correct value    stackoverflow.com

There is a slight part of my program that is not working correctly and I just cannot work out why

String KEY = "hello"
for (int h = 0; h < message.length(); h++)
{
 ...

19. Java do loop - string cannot be resolved    stackoverflow.com

Working on a simple dice rolling game using programmer defined methods in Java. Since I know the program needs to run at least once and then ask if the player wants ...

20. Reduce String.charAt to one loop during String comparison    stackoverflow.com

I need to compare two strings that are of varying length and as such I have written two conditional loops depending on which String is longest:

boolean compare(String first, String ...

21. how to find a 'carriage return' and loop back to main until user enters a string    bytes.com

P: 1 hopes excuse me, simple question I want a user to enter a string so that I may recursively call it to reverse it. Just one thing, i wanna make ...

22. loop through a string    coderanch.com

23. String display without any loops    coderanch.com

24. String and for Loop Confusion    coderanch.com

Good evening all, I've been staring at the below problem and am more confused than before hand. I've done strings before and replaced letters within them but never in a for loop. I've only used the replace method which is something that we cannot use. Any guidance would be greatly appreciated. Let word be a String variable referencing a non-empty string. ...

25. Sentinel-controlled loop with a String variable condition    coderanch.com

I'm pulling my hair out. I have a tiny, little Payroll program written. It asks for user input for name, hourly rate of pay, hours worked during week, calculates weekly pay, and displays all on the screen. It compiled and executed correctly. Now, however, I have to modify it with a loop that will use "stop" in the variable name as ...

26. Using a String variable as an object name in a loop...Possible??    coderanch.com

Hi is it possible to create objects when the object name is a variable? My code looks like this right now: public void createGrid(Graphics g2) { int xPos=50,yPos=50, boxNumber=0; for(int verCounter = 0; verCounter < size; verCounter++) { for(int horCounter = 0; horCounter < size*10; horCounter+=10) { String strBoxName = verCounter + "" + boxNumber; boxNumber++; int boxName = Integer.parseInt(strBoxName); strBoxName ...

27. For (String s:ar) loop.................    coderanch.com

28. String and enhanced for-loop    coderanch.com

29. Printing a String object without using loop    coderanch.com

Deepak Kumar Jena wrote:Thanks Fred, but a code snippet will be more helpful. We generally don't just give out answers. Too many folks would be tempted to use us to cheat on their homework. do you know what recursion is? Have you ever written a recursive function? It's a function that calls itself, each time reducing to a simpler case. Printing ...

30. Accessing odd and even list items of a String list in a single for loop    coderanch.com

Hi, Say I have a String List like so: List sampleList = Arrays.asList("first Even element", "First Odd element", "Second Even element", "Second Odd element"); I am trying to access all even elements and odd elements in the same for loop like so: for (int i=0; i

32. Need help writing program to compare 2 strings using a loop    java-forums.org

So I'm trying to write a program that will compare two strings. Basically I want it to see if the first string makes up the beginning of the second string and then tell me yes if it does and no if it doesn't. For example, If string 1 was test and string 2 was testing then it would say yes. If ...

33. While loop comparing strings from user    java-forums.org

write a short program which will run in a loop asking the user for input with a simple prompt (for example "-> "). This will run until the user hits the enter key with no input (entering a String of length 0). The program will then display the lowest and highest (in alphabetical order) of the entered Strings. For example running ...

34. exiting a while loop with a string    java-forums.org

Hello all...I seem to be having some trouble exiting a while loop with a string. This feels really embarrassing but here is my code: private static String strDifficulty() { String strDif; strDif = JOptionPane.showInputDialog("What difficulty setting would you like? Hard or easy?"); while (!strDif.equalsIgnoreCase("easy") || !strDif.equalsIgnoreCase("hard")); { strDif = JOptionPane.showInputDialog("Please enter in either 'hard' or 'easy'. Thank you."); } return strDif; ...

35. reverse a string with a while loop...    java-forums.org

i found it tricky, i need to reverse a string with a while loop, no recursions allowed, and i should do it by cutting the first letter, put it as a last one than the 2nd letter etc... i tried with all my power and i still get the same string... here's the code: public static String reverseIterative(String s) { int ...

36. Exiting a while loop using a String?    java-forums.org

I'm trying to make the program read in a list of name and ages (using JOptionPane). It's supposed to quit the loop when the name entered is "quit". I learned to use ".equals" instead of "==" or "!=", but now when I run the program, it doesn't look like it's doing anything. I'm not sure what to do. Also i'm trying ...

37. using a loop to form a string pattern    java-forums.org

import java.util.*; public class Pattern { public static void main(String [] args) { Scanner input = new Scanner(System.in); System.out.print("Enter String: "); String s = input.nextLine(); for(int i=0;i

38. string loop    java-forums.org

39. String in While loop    java-forums.org

I am trying to create a while loop that reads the users input which is string. If the string doesnt match it will ask the user again to give the input. When i tired to create while loop it doesnt exit even though the string match. here is something i did. System.out.println("What surface do you want?"); Scanner object = new Scanner(System.in);//creating ...

40. How to reverse a string using while loops?    java-forums.org

Loops can be used to count down as well as up. Set a variable to some value, loop while it is greater than (or equal to) zero, use methods of String class inside loop to do what you need. I have deliberately left a few details out so you can think for yourself how to do it.

41. using for-loop to print out a string    java-forums.org

I am to have four methods, each method will print out the same paragraph of information: "This program supports 4 functions: 1. Setup Shop 2. Buy 3. List Items 4. Checkout Please choose the function you want:" Except once I create the second method, the new paragraph doesn't print out, my code will only output my first method and then stop. ...

42. can't leave while loop when verifying strings    java-forums.org

Ok, this is a very miniscule part of a large project and I cannot seem to get this part to work right. Eventually this option (choice 1) will create new employees using arrayList, but right now I am just trying to get it to verify that either "salaried" or "hourly" is entered. otherwise it should keep in loop. no matter what, ...

43. Question about sentinal loops with strings    java-forums.org

import java.io.*; import javax.swing.JOptionPane; public class WritePayrollFile { static String year, month, day, name; static double weeklyhoursWorked, overtimehoursWorked, bonusPaid; public static void main(String[] args) { // TODO Auto-generated method stub writeData(); } private static void writeData() { // TODO Auto-generated method stub year = JOptionPane.showInputDialog("Enter Year of today: "); month = JOptionPane.showInputDialog("Enter Month of today: "); day = JOptionPane.showInputDialog("Enter day of ...

44. Please show an example of a String in a while loop.    java-forums.org

Would someone show me an example of a string in a while loop please? I have no idea how so I can't show you what I really meant but this is what I actually wanted to do. Basically what I wanted was while a user input (which is a name) is not equal to a string. So if someone enter a ...

46. Using a while loop and using a string variable to exit the program    java-forums.org

I had to delete my work because I got in trouble for plagiarizing my own assignment because of people stealing my code from here and submitting it as their own and my instructor caught it late, so as damage control and to hopefully show the university that this is in fact my own work, I am removing these posts with my ...

48. Stacks and Dequeue Logic Loop Help - Alphabetizing Strings    forums.oracle.com

That's pretty good thinking on trying to crack the system, which reminded me that the test Strings to be entered are given to us. Here are the test data strings and a sample output process of what should be returned from program. The deque displays front to back, as left to right. The stack displays top to bottom as left to ...

49. Scanner class, String comparisons and looping    forums.oracle.com

I have this code: if(mailer.equals("")){ mailer = buffer; sb.append(mailer +" firstTime" + "\n\r"); mailerCnt = 1; getFile(line); }else if (!mailer.equalsIgnoreCase(buffer)){ mailer=buffer; sb.append("\r\n" + mailer + "\n"); mailerCnt = 1; getFile(line); }else{ mailerCnt++; getFile(line); } that is comparing strings from scanner.next() elements, the second time through the loop it doesn't recognize that mailer variable is equal to buffer variable, and executes as ...

50. problem with a for loop replacing letters in a string    forums.oracle.com

yeah i give them the first letter to start off with so really they only have to guess the next 4 that way its not a complete blank at guessing. thats why i started the for loop at 1 and went to < 4 that way it would only check the next 4 letters of thier word (im giving the benifit ...

51. help with Strings and loops    forums.oracle.com

52. for loop with strings    forums.oracle.com

{ int f1 = firstName.length(); int m1 = middleName.length(); int l1 = lastName.length(); name = firstName.length()+middleName.length()+lastName.length(); //the length of input one + two + three == number of times output outputStr = String.format("First Name \n%s", firstName.toUpperCase() //first name to uppercase + " = " + f1 + " characters \n\n") + String.format("Middle Name\n%s", middleName.toUpperCase() //middle name to uppercase + " = ...

53. Loop with strings    forums.oracle.com

54. need help with a for loop - string checking    forums.oracle.com

56. declare many string by using for loop    forums.oracle.com

58. Question about while loops and strings    forums.oracle.com

59. not sure how to loop charAt for the length of a string    forums.oracle.com

If you had run the code I posted above you would see that it printed 0 over and over and over in an infinite loop because counter is 0 and 0 is less than 10 and counter never changes so the loop never ends. Think about that. Also you currently have your code printing the char at 0 everytime around the ...

60. Fastest way to loop through a group of strings    forums.oracle.com

sarcasteak wrote: I am assuming the same thing... unfortunately the vendor was giving me advice and I couldn't see the logic behind it. Never forget: many vendors are idiots. As already pointed out, switching to something like a binary search could speed up the search time, but it's almost certainly not worth it for a list with only 15 elements. The ...

61. String from for loop    forums.oracle.com

63. Trouble with charAt and nested for loops    forums.oracle.com

3a. Write a program that reads a social security number written as contiguous digits (for instance, 509435456), uses the charAt method to obtain each character and then prints each digit on a separate line followed by a colon and the digit printed the number of times equal to its value. Thus the output for 509435456 would be

64. Create Multiple Strings with a for loop.    forums.oracle.com

65. Reversing a string with for loop    forums.oracle.com

Hi, first time poster here. I'm a total beginner at programming and I want to make a method that reverses the order of characters using a for loop. I was able to do the reversing like this: Code: StringBuffer mjonoBuff = new StringBuffer(mjono); painvastainen = mjonoBuff.reverse().toString(); System.out.println(painvastainen); But I need do it as a method and using a for loop. I ...

66. for loop with string    forums.oracle.com

67. output strings from loop into one string    forums.oracle.com

68. need some help with strings and loop    forums.oracle.com

70. creating a string from a for loop?    forums.oracle.com

You can put almost anything in a StringBuffer append. And if you want to print something, then don't do it in your toString method. Either have something else call toString and then print the result, or don't create a toString method (call it something else). What precisely do you want to put into the String that you think you can't do ...

71. While Loops with Search Strings    forums.oracle.com