• Post Reply Bookmark Topic Watch Topic
  • New Topic

help me to debug please  RSS feed

 
catherine matthews
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..... what i am trying to find is the corresponding open and closing brackets..... in order to find the methods with a java program...
Am i doing it right??? i am still not getiung the output i wanted... where is my mistake...??? please help me....

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without seeing what output the code produces for a particular input it's hard to say what might be going wrong.

Assuming that "output" is a string of Java code, I notice that you don't check for comments or strings. Brackets that occur in either could throw the code off balance.

I'm also not sure that the code correctly handles the case where one of the tokenized items contains both opening and closing brackets.
 
catherine matthews
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the out put that i got when i input a java file... From there i tokenized the words and put it inside an array.....

the words are 0 ========public
the words are 1 ========class
the words are 2 ========AccountRecord{
the words are 3 ========private
the words are 4 ========int
the words are 5 ========account;
the words are 6 ========private
the words are 7 ========String
the words are 8 ========firstName;
the words are 9 ========private
the words are 10 ========String
the words are 11 ========lastName;
the words are 12 ========private
the words are 13 ========double
the words are 14 ========balance;//
the words are 15 ========the
the words are 16 ========defoult
the words are 17 ========constructor
the words are 18 ========public
the words are 19 ========AccountRecord()
the words are 20 ========{
the words are 21 ========this
the words are 22 ========(
the words are 23 ========0,"",
the words are 24 ========"",
the words are 25 ========0.0);
the words are 26 ========}
the words are 27 ========public
the words are 28 ========AccountRecord
the words are 29 ========(int
the words are 30 ========acct,
the words are 31 ========String
the words are 32 ========first,
the words are 33 ========String
the words are 34 ========last,
the words are 35 ========double
the words are 36 ========bal)
the words are 37 ========{
the words are 38 ========setAccount
the words are 39 ========(acct);
the words are 40 ========setFirstName
the words are 41 ========(first);
the words are 42 ========setLastName
the words are 43 ========(last);
the words are 44 ========setBalance
the words are 45 ========(bal);
the words are 46 ========}//
the words are 47 ========the
the words are 48 ========variable
the words are 49 ========constructor
the words are 50 ========public
the words are 51 ========void
the words are 52 ========setAccount
the words are 53 ========(int
the words are 54 ========acct)
the words are 55 ========{
the words are 56 ========account
the words are 57 =========acct;
the words are 58 ========}
the words are 59 ========public
the words are 60 ========int
the words are 61 ========getAccount()
the words are 62 ========{
the words are 63 ========return
the words are 64 ========account;
the words are 65 ========}
the words are 66 ========public
the words are 67 ========void
the words are 68 ========setFirstName(
the words are 69 ========String
the words are 70 ========first)
the words are 71 ========{
the words are 72 ========firstName
the words are 73 =========
the words are 74 ========first;
the words are 75 ========}
the words are 76 ========public
the words are 77 ========String
the words are 78 ========getFirstName()
the words are 79 ========{
the words are 80 ========return
the words are 81 ========firstName;
the words are 82 ========}
the words are 83 ========public
the words are 84 ========void
the words are 85 ========setLastName(
the words are 86 ========String
the words are 87 ========last)
the words are 88 ========{
the words are 89 ========lastName=
the words are 90 ========last;
the words are 91 ========}
the words are 92 ========public
the words are 93 ========String
the words are 94 ========getLastName()
the words are 95 ========{
the words are 96 ========return
the words are 97 ========lastName;
the words are 98 ========}
the words are 99 ========public
the words are 100 ========void
the words are 101 ========setBalance(
the words are 102 ========double
the words are 103 ========bal)
the words are 104 ========{
the words are 105 ========balance
the words are 106 =========bal;
the words are 107 ========}
the words are 108 ========public
the words are 109 ========double
the words are 110 ========getBalance
the words are 111 ========()
the words are 112 ========{
the words are 113 ========return
the words are 114 ========balance;
the words are 115 ========}}
{ starts here2
{ starts here20
} closes here26
{ starts here37
} closes here46
{ starts here55
} closes here58
{ starts here62
} closes here65
{ starts here71
} closes here75
{ starts here79
} closes here82
{ starts here88
} closes here91
{ starts here95
} closes here98
{ starts here104
} closes here107
{ starts here112
} closes here115
Method 117 - start at 111 and ends at 0
Method 117 - start at 0 and ends at 0
Method 117 - start at 0 and ends at 0
Method 117 - start at 0 and ends at 0
Method 117 - start at 0 and ends at 0
Number of words : 120
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. And what did you expect instead?
 
catherine matthews
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i wanted to have.....
method 1 starts at 2 and ends at 26
method 2 starts at 20 and ends at 37
it would have 5 output because i had intialized
int method[][] = new int [5][2]

actually my
concept was okie when tried like below.........

where is my mistake???
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're allocating method[][] for each new word; I think you should do that only once before starting the iterator.

The code also doesn't differentiate between brackets used for a) classes, 2) methods and c) if, for and while statements, so it's counting way too many.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!