import java.util.Scanner;
    public class Program2{
        public static void main (String []args) {
            Scanner input = new Scanner (System.in);
            int[] data = new int[256];
            int inAscii;
            char inChar;
            String inString= input.nextLine();
            for (int i = 0; i < inString.length();i++) {
            inChar=inString.charAt(i);
            inAscii=(int) inChar;
            data[inAscii]++;
            }

            for (int i= 1; i<256; i++){
                int[] count= new int[256];
                if (count[i] !=0){
                    if(count[i] > 1)
                        System.out.printf(" character: %c, ASCII#: %3d, occurs %2d times\n", 
                                (char)i , i , data[i]);
                    else 
                        System.out.printf("character: %c, ASCII: %3d, occurs %2d time\n", 
                                (char)i, i,data[i]);

                }
            }
        }
        }

`this is what i have so far and i wanna knbow what is missing..
the output should look like this:
Input:

Please enter a string and press ENTER to end.
int i=1;i++,1=1;

Output:
character: , ASCII#: 32, occurs 1 time
character:+, ASCII#: 43, occurs 2 times
character:,, ASCII#: 44, occurs 1 time
character:1, ASCII#: 49, occurs 3 times
character:;, ASCII#: 59, occurs 2 times
character:=, ASCII#: 61, occurs 2 times
character:i, ASCII#:105, occurs 3 times
character:n, ASCII#:110, occurs 1 time
character:t, ASCII#:116, occurs 1 time
Program 2 is developed by

Recommended Answers

All 17 Replies

Member Avatar for iamthwee

You mean something like this?

vv.jpg

Yea something like that just It asks for the string and then u enter the string to use then press enter

the only thing I see missing is that line "Program 2 is developed by", but since you didn't coded it, it isn't missing, it's just not there yet.

I know but I have the issue that it doesn't count the string that is inputted .. It's just terminates so I'm lost on what I need and running out time for its time of being due ..

Line 16 you create a new array of ints. You don't provide any initialisation, so all the elements are 0.
Lines 17-25 are only executed if the array elements are not 0 - so they are never executed.

so what should do I'm confused on this program ..

Switch off your computer.
Get some paper and pencil. Work through a couple of short examples on paper until you have a solid grasp of what to write down and how to do the calculations etc. Then, and only then, turn the computer back on and write a program to implement what you now know.

commented: I like this, not enough compsci students do this +14

Ok .. I can try that it's just I'm short on time ..

It may sound slow, but believe me, it's even slower to keep trying random changes to code when you don't understand what the code should be doing...

ps: Why two user IDs?

ones from a laptop and the other from my cell .. im lost in the code because i keep geting an error at line 20 .

i keep getting Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:
how do i fix this im runnig out of time and still learing java

Member Avatar for iamthwee

The error means you're stepping outside the bounds of the array. Clue: think about why this is happening? Try doing a print out within the for loop to figure out why and setting i<256 to something smaller so it runs.

ok i can try to reduce the size im just wanna get the programm done and im lost

Member Avatar for iamthwee

ok i can try to reduce the size im just wanna get the programm done and im lost

The only way to get unlost is to understand where you're going wrong this took me no more than 2 minutes to write.

If you get stuck you can ask more questions and we'll guide you.

trev.jpg

well i reduced and still got the same error and its due then less then 40 mins

Member Avatar for iamthwee

Hmm, OK well in this instance you've probably left it too late.

Whilst I know you're fishing for someone to post a full solution -like I could, we won't. Simply because while it may help you in the short term, it won't help you in the long run.

Take this as a lesson, to one plan your assignments much earlier, and two use plenty of system.println() in your code to figure out where your errors are - If you're not using a debugger of course.

Had you done this we would have pushed you in the right direction. Good luck pal.

i havent left this to last minute ive been working on it for a few days im just still learning java and this program is just giving me some problems ..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.