User Profile

Collapse

Profile Sidebar

Collapse
SuperDuper
SuperDuper
Last Activity: Oct 18 '07, 08:25 PM
Joined: Oct 3 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Can somebody please help me?
    I'm super stuck, yet I'm sure there's an easy way out.

    I want to add up the length of each word.. in the code i'll provide, it has 2 words.

    The output is:
    1.0
    2.0
    Whitespace
    1.0
    2.0
    3.0
    4.0
    Last Word Length: 4.0
    Number of words: 2.0
    Average Word Length: 2.0


    As you can see, the "2.0"...
    See more | Go to post

    Leave a comment:


  • Okay well I think I've figured out how to count words.
    My code is posted below.

    Although at the top, where I have Line = SomeStrings.s1;
    it won't refer to the .class file in my Java Folder.

    I know the SomeStrings.cla ss is properly placed because if I set up a println it *will* print out the string.

    Although I can't when set as above.

    Any thoughts?

    Code:
    ...
    See more | Go to post

    Leave a comment:


  • Okay well now I have this.
    [PHP]
    import java.util.Scann er;
    public class Word
    {
    public static void main(String []args)
    {
    int count = 1;
    String line = SomeStrings.s1;
    long numWords = 0;
    int index = 0;
    boolean prevWhitespace = true;
    while (index < line.length()) {
    char c = line.charAt(ind ex++);

    boolean currWhitespace =...
    See more | Go to post

    Leave a comment:


  • Hah, yes that's me.
    I've passed in the last assignment, and I had no troubles.
    I'm not allowed to implement arrays/string tokens, etc.. (theoretically) because my uncle has yet to teach us, so I can't jump ahead.

    I have an idea of how to count the words.. my current code is as follows:

    [PHP]import java.io.*;
    public class WordCount
    {
    public static void main(String SomeStrings.s1,...
    See more | Go to post

    Leave a comment:


  • Just a few quick questions about Strings. Thank you!

    Just a few quick questions.

    1) How would I count the length of words in 5 certain strings.
    SomeString.s1, SomeString.s2, etc..

    2) How to compute the average word length?

    3) How to compute the standard deviation (without duplicating code)

    4) How to do all of this without duplicating the code for each String.

    If anyone knows the answer to any of these questions, please...
    See more | Go to post

  • SuperDuper
    replied to Nim program.
    in Java
    What do you mean by exceptional condition?

    How do I solve this?
    I keep being told what the problem is.. and then left to dwell over it..

    should I just put in a for loop? if so.. what should be in the for loop?
    I don't need to know why.. once I see the code.. or an example then I'll be able to figure it out.

    anybody?...
    See more | Go to post

    Leave a comment:


  • SuperDuper
    replied to Nim program.
    in Java
    Is it because I have

    [PHP]System.out.prin tln("|||||".sub string(0, Row1));

    System.out.prin tln("|||||".sub string(0, Row2));

    System.out.prin tln("|||||".sub string(0, Row3));

    System.out.prin tln("|||||".sub string(0, Row4));


    that I get an error whenever I try to remove less than zero (0) sticks...
    ...
    See more | Go to post

    Leave a comment:


  • SuperDuper
    replied to Nim program.
    in Java
    I'm trying to make it so.. IF somebody inputs an incorrect number (irrelevant to the program's main purpose)

    Ex: chose the 7th row.. or chose to remove 50 sticks..

    I just want it to ignore all these cases and continue.. that's why I set each Row equal to a different variable.. so I thought I had the right process.. just obviously in an incorrect syntax.

    Can somebody please post the correct way to do this.....
    See more | Go to post

    Leave a comment:


  • SuperDuper
    replied to Nim program.
    in Java
    I'm using "5" .. so a hardcoded number.

    I tested out using something like this.

    [PHP]
    int a = Row1;
    int b = Row2;
    int c = Row3;
    int d = Row4;
    int e = Row5;


    if (x > a,b,c,d,e || y > a,b,c,d,e || y>x)
    {
    System.out.prin tln("Please enter a correct number");
    ...
    See more | Go to post

    Leave a comment:


  • SuperDuper
    replied to Nim program.
    in Java
    Thank you so much, that basically did what I wanted it to..

    For example I choose the fifth row, to remove 6 sticks.. and it prints out "please choose a correct number"..

    although since my code is
    [PHP] if (x > 5 || y > 5 || y > x)
    {
    System.out.prin tln("Please enter a correct number");
    continue;
    }[/PHP]

    once you remove...
    See more | Go to post

    Leave a comment:


  • SuperDuper
    replied to Nim program.
    in Java
    It doesn't matter what they type.. if it is irrelevant to the actual purpose of the program.. it can simply be ignored. There does *not* need to be any code written for such as the 4 exceptions you've posted.

    It just simply needs to ignore it..and continue on.

    The program would ask: Player A Which row would you like to use? Answer: 7
    How many sticks would you like to remove? Answer: 62

    Then it...
    See more | Go to post

    Leave a comment:


  • SuperDuper
    replied to Nim program.
    in Java
    Wow, that basically completed the program right there.
    The only thing is if I try to remove three(3) sticks from the second row, then it prints out an ugly section of errors.

    I'd rather it just simply ignore the choice, and remove the maximum from that row.. Ex: Removing five(5) sticks from the third row would print: " " (nothing).

    I also have to see if I'm able to use Substrings, but I should be...
    See more | Go to post

    Leave a comment:


  • SuperDuper
    replied to Nim program.
    in Java
    Okay, that makes sense.. I've applied the necessary changes and it seems to do what I want.. although when it prints out the line.. since each one is a print(blah blah)

    as opposed to a println( blah blah) .. then the WHOLE board (all rows) are printed onto the same row... but if I switch it to be println(blah blah) then each time it runs through each individual for loop it puts a new stick on a new line..

    how do I solve...
    See more | Go to post

    Leave a comment:


  • SuperDuper
    replied to Nim program.
    in Java
    My main objective is to solve the program, I do not care which way it is implemented as long as it completes the required task.

    Efficiency is not an issue, so more beneficial methods are irrelevant. Reading the previous posts would support this.

    Thank you to everyone who posted solutions, i'll try them out and report back....
    See more | Go to post

    Leave a comment:


  • SuperDuper
    replied to Nim program.
    in Java
    I changed it to be

    .....
    [PHP]int difference = x-y;
    switch (x)
    {
    case 5:
    Row5 -= y;
    for (Row5=1; Row5 <= difference; Row5++)
    {
    System.out.prin t(" | " + " ");

    }
    [/PHP]
    This prints out the right amount of sticks the first time.. for example.
    x=5 (Row5) and y=3...
    See more | Go to post

    Leave a comment:


  • SuperDuper
    replied to Nim program.
    in Java
    Okay I've made progress..

    I'm now able for PlayerA and PlayerB to choose any row, and any amount of sticks to remove.

    It prints out the board after each turn, except in the form of numbers..
    how do I make it so it prints out the sticks?

    That may be the end of it, if I can finish that. :)

    [PHP]import java.util.Scann er;
    public class StickGame
    {
    public static...
    See more | Go to post

    Leave a comment:


  • SuperDuper
    replied to Nim program.
    in Java
    PS - Why would I want
    while (Row1 != 0 && Row2 !=0 && Row3 !=0 && Row4 != 0 && Row5 != 0)

    to be "|| " (Or) instead?

    wouldn't that only run the loop until ONE row equals zero?
    Even though I want ALL rows to equal zero before the loop stops, and then print "You Win!"
    See more | Go to post

    Leave a comment:


  • SuperDuper
    replied to Nim program.
    in Java
    what do you mean by "a single initial String "|@||@|||@||||@ ||||@"

    I'm pretty much a novice in the field of programming..
    I felt as if I was nearing completion of this program, but I don't know which suggestion to follow through with.

    Right now I have my Rows as follows:
    [PHP] int Row1 = 1;
    int Row2 = 2;
    int Row3 = 3;
    int Row4 = 4;
    int Row5...
    See more | Go to post

    Leave a comment:


  • SuperDuper
    replied to Nim program.
    in Java
    Thanks a lot for your suggestion,
    would that be considered a second method though?

    The requirements state I can only use a single method (main).. no arrays..

    no only the basics.. int, double, String, for, while, if/else, println, print, etc.
    See more | Go to post

    Leave a comment:


  • SuperDuper
    replied to Nim program.
    in Java
    Alright, I appreciate your clarification,

    basically I don't expect to take any other courses in Programming, so I'm just wanting to finish this up.. It doesn't matter if it's the most efficient method at all, just needs to work.

    Here's my current code, can somebody post the remaining pieces that I need, either the code.. or a description of what I need to do.. I'm getting quite desperate, i'll admit.. so I really appreciate...
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...