Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why wont this run

 
tom brownlee
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys..i have this code to count a character within a given source file..why wont it run/(it doesnt seem to compile either)
import java.io.IOException;
class Main
{
public static void main( String args[] )
{
try
{
int count = 0;
int ch = System.in.read();
while ( ch == '/')
{
count++;
ch = System.in.read();
}
System.out.println( "Total number of characters: " + count );
}
catch ( IOException err )
{
System.out.println("Unexpected error on
input");
}
}
}

any help?
also i have this code (below) for calculating the lines in a source code (any random source code) how can i combine both codes (above and below) to produce code that will calculate the amount of logical lines in a source code?
ive asked b4, given it ago, but im stuck at this point..can i get the answer???
thanks guys for your time and effort
cheers
tom
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by tom brownlee:
sorry guys i forgot to add this code to my question previously:
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by tom brownlee:
just a thought...my previous question didnt ask one important thing....
how can i ask for a source code from the user to enable my code to be used.
ive got this code..but how do i use it in cooperation with my other code?

so i really suppose my entire question would be..how do i combine this code here, along with my code from my previous question to enable a user to enter a source code name and for the code to reply with the number of logical lines within that source code.
make sense?
once again thanks for the time on this guys. i really appreciate it.
tom
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom,

It's easier to answer your questions if you keep your questions regarding the same thing in the same thread rather than three separate threads.

I've moved them all here for you this time.

Just hit the reply button and add your code or alternatively, you can hit the edit button and add it into the same post.
[ April 08, 2002: Message edited by: Marilyn deQueiroz ]
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code #1 (class Main)
will compile if you don't split your String between two lines.

System.out.println("Unexpected error on
input");

should be

System.out.println("Unexpected error on input");

or

System.out.println("Unexpected error on " +
"input");
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps it would be better if you had three methods rather than three classes.
 
tom brownlee
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry marilyn
i think it must of been the way i wrote the code out...it should be on one line...with that solved it still doesnt compile.
any reason why?
and when i use methods instead of classes it still doesnt work?
any idea why?
 
Rob Keefer
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code #1 works for me ...
Maybe you can give a bit more detail about the version of the compiler, os, compile error you get, etc.

import java.io.IOException;
class Main
{
public static void main( String args[] )
{
try
{
int count = 0;
int ch = System.in.read();
while ( ch == '/')
{
count++;
ch = System.in.read();
}
System.out.println( "Total number of characters: " + count );
}
catch ( IOException err )
{
System.out.println("Unexpected error on input");
}
}
}
/Development/Java/tmp>javac Main.java
/Development/Java/tmp>java Main
///////
Total number of characters: 7
 
Rob Keefer
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code #2 works for me also:
/Development/Java/tmp>javac Line2.java
/Development/Java/tmp>java Line2 Main.java
24

Again, more information would be helpful ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic