Search:

Type: Posts; User: BenjaminJ

Page 1 of 2 1 2

Search: Search took 0.17 seconds.

  1. Replies
    7
    Views
    1,731

    Re: Creating a separate method for for loop

    Partially - I was hoping to get the index of every character individually. So 'abc' would be '123' and then '123' would act as the seed for the psuedo-random number generator. Maybe a for loop isn't...
  2. Replies
    7
    Views
    1,731

    Re: Creating a separate method for for loop

    So, instead of:



    alphabet.indexOf(tokens[i]);

    int result = tokens[i];


    it should be
  3. Replies
    7
    Views
    1,731

    Re: Creating a separate method for for loop

    Okay, is that better?
  4. Replies
    7
    Views
    1,731

    Creating a separate method for for loop

    I'm trying to create a PRNG which takes a seed through Scanner.

    Here's the (terrible) code:



    import java.util.*;

    public class Numbers {
  5. Re: Identical if statements behaving in different ways

    Okay, so, my program needs to match this: Maisto Ford Mustang Limited Edition 1:18 Red
    with "Mustang" but not to "Ion"

    Sample input and output:

    INPUT:

    Maisto Ford Mustang Limited Edition...
  6. Re: Identical if statements behaving in different ways

    This is the part I updated.


    for (int i=0; i<scaleList.length; i++)

    if (title.toLowerCase().lastIndexOf(scaleList[i].toLowerCase())!= -1)

    { scale = scaleList[i];
    ...
  7. Re: Identical if statements behaving in different ways

    Well, another issue has come up. For example with a model of a 'GT500' the program reacts by matching that first with 'GT' and settling with that. I've tried '.contains', I've tried .indexOf != -1,...
  8. Re: Identical if statements behaving in different ways

    You're right, I've reduced the block of if statements to nine lines in total. And the problem, originally, was the way I joined new lines with +s instead of just pressing enter and typing a comma.
  9. Identical if statements behaving in different ways

    I'm writing a program which takes the title of a model car and breaks the elements down into HTML metadata.

    All of the car companies (Ford, etc.) are in an array, which is called upon to be...
  10. [SOLVED] Re: Potentially broken switch statement or program logic.

    Yes, sorry, it was a case of curly brace confusion once again.
  11. [SOLVED] Potentially broken switch statement or program logic.

    The premise is a brute force search for an inputted string. Based on the length of the inputted string (1-4) the switch statement executes one of four blocks which should break when it finds the...
  12. Re: if statement - might have problem with char to String casting?

    Would you mind naming the method? I'm only just starting to learn the String class.

    And thanks jdv for the information, much appreciated.
  13. Replies
    4
    Views
    910

    Re: HOW to do it?

    You could try a string array containing every stage of the dot pattern and having a for loop cycle through the elements.
  14. Re: if statement - might have problem with char to String casting?

    So I'd have the array which would have a .length as the amount of items as chars inputted by the user? Then what would I do with that array? Surely there'd be an amount of possibilities which I'd...
  15. Re: if statement - might have problem with char to String casting?

    Oh! Excellent. That totally slipped my mind. Why is not giving me an error, in that case? Is there any way of modifying this code so the user can input a string of any length they choose? I assume...
  16. Replies
    3
    Views
    800

    Re: Date conversion in java..

    Hi there,

    For people to help it's useful if you put [ code=java] [ /code] (without spaces) around your code, and also paste the sample output.

    Thanks
  17. if statement - might have problem with char to String casting?

    import java.io.IOException;
    import java.util.*;
    public class Guesser {
    public static void main(String[] args) throws IOException {

    char[] alphabet = "abcdefghijklmnopqrstuvwxyz1234567890...
  18. Re: Print variable which only exists within for loop?

    int[] onetoTen = {1,2,3,4,5,6,7,8,9,10};
    int sum = 0;

    for (int i=0; i<10; i++) {



    sum +=onetoTen[0]++;
    System.out.println(sum);
  19. Re: Print variable which only exists within for loop?

    Okay, thank you both that worked fine, does that mean that it needs to be declared in main only? I tried it in main and that worked, but would it work if it were to be declared in another method?
    ...
  20. Print variable which only exists within for loop?

    There's loads of problems with this. What I'm trying to do.

    1) get a program to add the contents of an array together, preferably with a for loop and not the heavy handed version I've tried to...
  21. Re: Randomise Placement of Variables in Outputted String

    Thanks for the suggestions but I think that it might be beyond my capabilities right now - I understand the logic but not how to implement it.
  22. Randomise Placement of Variables in Outputted String

    public class PasswordGen {

    public static void main (String[] args) {

    Generator();

    }

    public static void Generator() {
  23. [SOLVED] Re: Random 4 Char Generator Generates 3 Numbers Instead?

    I just realised the answer myself - the only part looping was the print method, not the random number generator. Everything's solved, thanks guys.
  24. Replies
    4
    Views
    1,203

    Re: incompatible types

    You would want to do this with a for loop, I think.

    for (int i = 0; i < 500; i++) {
    System.out.println(i);
    }

    Unless you're practicing while/if, in which case I'm not sure.
  25. [SOLVED] Re: Random 4 Char Generator Generates 3 Numbers Instead?

    I thought I just replied to this, but my post disappeared. Thanks for your concise reply - I have another question; when I put the random number generator in a for loop, it returns the same result...
Results 1 to 25 of 27
Page 1 of 2 1 2