Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: hi its mery , and iam new i have this code

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Location
    JAVA Forums
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default hi its mery , and iam new i have this code

    i have this code :

    public class NewClass {

    public static void main(String[] args) {
    String s = JOptionPane.showInputDialog("Enter a string:");
    int[] counts = countLetters(s.toLowerCase());
    String output = "";
    for (int i = 0; i < counts.length; i++) {
    if (counts[i] != 0)
    output += (char)('a' + i) + " appears " +
    counts[i] + ((counts[i] == 1) ? " time\n" : " times\n");
    }
    JOptionPane.showMessageDialog(null, output);
    }
    public static int[] countLetters(Sring s) {
    int[] counts = new int[26];
    for (int i = 0; i < s.length() ; i++) {
    if (Character.isLetter(s.charAt(i)))
    counts[s.charAt(i) - 'a']++;
    }


    return counts;

    but i need to appears letter A times only , not all litters, plz help me


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: hi its mery , and iam new i have this code

    Change the code inside the loop in the count method to test each character in the String against the desired letter and to increment the count when the desired letter is found.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Hi Members , its Mery ! I am New User And need Help ^_^
    By meryqat in forum Java Theory & Questions
    Replies: 1
    Last Post: March 23rd, 2012, 12:46 PM
  2. code to refresh and check the code of a webpage..
    By vaggelis in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 7th, 2012, 07:43 AM
  3. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 08:36 AM
  4. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM
  5. describe this program code by code ....
    By izzahmed in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 29th, 2011, 11:03 PM