We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,401 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

java problem plzz help

Write a program that reads characters from the keyboard until a period is
received. Have the program count the number of spaces and display it to the
user. After that, ask the user if he/she would like to count a specific character.
Terminate when the user is done counting the characters.
plzzz help me

2
Contributors
3
Replies
43 Minutes
Discussion Span
1 Year Ago
Last Updated
4
Views
tartosha
Newbie Poster
2 posts since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

what help do you need?
you know what to do, the only thing you need to actually create and test that application is a keyboard, and since you've been able to write that post, I 'm pretty sure you already have one.

show us the code you've written and where you 're stuck, but we're not going to write code-on-demand.

stultuske
Industrious Poster
4,382 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24
import java.util.Scanner;
public class Characters 
{
    public static void main(String args[])
    {
        Scanner input = new Scanner(System.in);
        char ch; 
        int spaces = 0; 
        System.out.println("Enter . to stop."); 
        while(ch != '.') 
        { 

              ch = (char) System.in.read();
              System.out.println(ch); 
              spaces++;


         }
        System.out.println("number of spaces : "+spaces);
        System.out.println("would like to count a specific character(yes or no) : ");

    } 
}

I don't know how to count a specific character

tartosha
Newbie Poster
2 posts since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

first: let him choose yes or no, if yes, let him choose a certain char, which you store in a variable.

you're already comparing them to '.' so you know how to compare them ( if char == testChar)
also, at the start of your app, initialize an int counter and set it to 0;

if ( charIJustRead == testChar)
counter += 1;

stultuske
Industrious Poster
4,382 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0656 seconds using 2.68MB