• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

[NEWBIE] Project assignment question - Given an array of strings, output the total number (n) of characters in the list

Question

kukubau    9

Hi all

 

I have a project assignment tomorrow at noon, call it homework. I have to write an algorithm, write the pseudocode and draw a flowchart.

 

Given an array of strings, output the total number [n] of characters in the list. Basically to count all the letters that occur in my string list. All the model algorithms similar I've found are counting the occurrences of a certain letter in the string. I don't need that, I just want the number of strings to be printed, but I don't have any restrictions how many times they should occur or not.

 

Example: a = ["Tom", "has", "books"] => n = 11; for a = [] (empty array, with no elements), n = 0.

 

I am a total beginner so bare with me.

 

I have found a javascript "pseudo"code that does what I need, but I have to translate this in a layman's pseudocode and draw a diagram.

String input = ["Tom", "has", "books"];

int count = 0;
for (int i=0; i<input.length(); i++) {
    if (input.charAt(i) != ' ') {
        ++count;
    }
}
System.out.println(count);

Muchos gracias.

 

kukubau

 

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0
DevTech    1,517

"Light travels faster than sound. That's why some people appear bright until you hear them speak."

 

1. simply looking at a few posts would have informed you that help on homework is not likely to happen unless you are bright enough to phrase a question so it appears like a "real world" problem.

 

2. Flowcharts have not been spotted since the 1970's and those golden years of IBM Mainframes, so unless you own a T.A.R.D.I.S, and have a regular consulting gig back in the 1950's at UNIVAC, save some neurons and paper and aggravation and yeah there is always "that guy" who pulls out a flowchart in 2017 and everyone groans. Do you want to be That Guy?

 

3.  Pseudocode still has a tiny core of retro holdouts that are still trying to channel the spirit of PASCAL but unless you have a sister that cries a lot, do you really want to join the Lost Boys? (https://www.youtube.com/watch?v=mrMLMV6E4CM)

Share this post


Link to post
Share on other sites
  • 0
kukubau    9

You sir made my day. :))

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.