0
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

5
Contributors
17
Replies
73
Views
2 Years
Discussion Span
Last Post by Trevor_5
Featured Replies
  • 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 … Read More

0

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

0

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.

0

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 ..

0

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.

Edited by JamesCherrill

1

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.

Votes + Comments
I like this, not enough compsci students do this
0

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?

0

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

0

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

0

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.

Edited by iamthwee

0

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

0

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

0

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

0

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.

Edited by iamthwee

0

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 ..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.