Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Article Writing
  4. Help with program for counting using hashtable

Help with program for counting using hashtable

Scheduled Pinned Locked Moved Article Writing
questionjavacomhelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    john kappas
    wrote on last edited by
    #1

    I want to create a programm that would read data from a file and will put each distinct item in a hashtable,counting how often it appears.I want to count first how often single characters or numbers appear,then how often the combination of two characters appear,three characters etc. More specifically... How can I use hashtable to count the appearances of some items in a file.For example how often is the letter a used,letter b etc.I am using hashtable.class in java.util.* ,but what I can not do is associate each letter that I am reading with a place in the hashtable. For example the following code creates a hashtable called numbers with the default capacity and load factor.Then one-two-three are used as the keys and 1-2-3 as the values. Hashtable numbers = new Hashtable(); numbers.put("one", new Integer(1)); numbers.put("two", new Integer(2)); numbers.put("three", new Integer(3)); I want my hashtable to read a file one character or one number at a time and count their appearances. The data would most probably be in the form abc abcd a abce ecf e fg or 123 12346 12 348 7 2 3456 52 364725 Thanks a lot for suggestions to my previous question as well as to future ones. jkouris@hotmail.com

    L 1 Reply Last reply
    0
    • J john kappas

      I want to create a programm that would read data from a file and will put each distinct item in a hashtable,counting how often it appears.I want to count first how often single characters or numbers appear,then how often the combination of two characters appear,three characters etc. More specifically... How can I use hashtable to count the appearances of some items in a file.For example how often is the letter a used,letter b etc.I am using hashtable.class in java.util.* ,but what I can not do is associate each letter that I am reading with a place in the hashtable. For example the following code creates a hashtable called numbers with the default capacity and load factor.Then one-two-three are used as the keys and 1-2-3 as the values. Hashtable numbers = new Hashtable(); numbers.put("one", new Integer(1)); numbers.put("two", new Integer(2)); numbers.put("three", new Integer(3)); I want my hashtable to read a file one character or one number at a time and count their appearances. The data would most probably be in the form abc abcd a abce ecf e fg or 123 12346 12 348 7 2 3456 52 364725 Thanks a lot for suggestions to my previous question as well as to future ones. jkouris@hotmail.com

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      const f = "C:\...\file.txt"
      set fso = CreateObject("Scripting.FileSystemObject")
      redim count(255)
      set ts = fso.OpenTextFile(f)
      do while not ts.AtEndOfStream
      c = asc(ts.Read(1))
      count(c) = count(c) + 1
      loop
      ts.close
      set ts = fso.CreateTextFile(f & ".count")
      ts.WriteLine "asc" & vbTab & "chr" & vbTab & "count"
      for i = 0 to 255
      if count(i) > 0 then ts.WriteLine i & vbTab & chr(i) & vbTab & count(i)
      next
      ts.close

      input: your mail output: asc chr count 10 (LF) 37 13 (CR) 37 32 176 34 " 6 40 ( 7 41 ) 7 42 * 1 44 , 8 45 - 4 46 . 19 49 1 5 50 2 8 51 3 7 52 4 4 53 5 3 54 6 3 55 7 2 56 8 1 59 ; 4 61 = 1 64 @ 1 70 F 2 72 H 3 73 I 10 77 M 1 84 T 3 97 a 102 98 b 24 99 c 39 100 d 20 101 e 115 102 f 20 103 g 12 104 h 47 105 i 38 106 j 2 107 k 3 108 l 38 109 m 25 110 n 57 111 o 61 112 p 22 113 q 1 114 r 53 115 s 52 116 t 94 117 u 31 118 v 3 119 w 23 120 x 2 121 y 6

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups