Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 7th, 2014, 07:28 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Mar 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default help with a java script

im trying to fix my java script to count the dots. here is my code if any one can help. i had it set up to count spaces but cant figure out the dots lol
import java.util.Scanner;
public class Assign5_blanton
public static void main (String[] args)
String phrase; // a string of characters
int countdots; // the number of dots
//Initialize input
Scanner scan = new Scanner(System.in);

// Print a program header
System.out.println ();
System.out.println ("Character Counter");
System.out.println ();

// Read in a string
System.out.print ("Enter dots: ");
phrase = scan.nextLine();

// Initialize counts
countdots = 0;

// a for loop to go through the string character by character

for(int i=0; i < phrase.length(); i++)
if(phrase.charAt(i) == ' ')


// Print the results
System.out.println ("Number of dots: " + countdots);
System.out.println ();
//Close input
Reply With Quote
  #2 (permalink)  
Old March 10th, 2014, 05:59 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

You need to understand the difference between Java and JavaScript, this forum is for the latter.

That being said there are two ways to attack this problem (maybe more...). One is to loop through the string and count the dots (by comparing to '.'), the other is to remove all non-dots (possibly with a regular expression) and then to get the length of the remaining string.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Example of Java script in c# arunumane2002 Javascript How-To 4 March 14th, 2017 07:43 AM
java Script raj1_syed Javascript How-To 1 August 17th, 2006 01:49 PM
java script nalla ASP.NET 1.0 and 1.1 Professional 8 June 23rd, 2006 06:24 AM
java script madangcse@gmail.com Javascript How-To 1 March 22nd, 2006 04:10 AM
Java vs Java Script functions joemorrison74 J2EE 0 July 6th, 2005 04:28 PM

All times are GMT -4. The time now is 05:20 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.