aspose file tools*
The moose likes Beginning Java and the fly likes why wont this run Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why wont this run" Watch "why wont this run" New topic
Author

why wont this run

tom brownlee
Greenhorn

Joined: Aug 14, 2001
Posts: 28
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

Joined: Jul 22, 2000
Posts: 9046
    
  10
Originally posted by tom brownlee:
sorry guys i forgot to add this code to my question previously:


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
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

Joined: Jul 22, 2000
Posts: 9046
    
  10
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

Joined: Jul 22, 2000
Posts: 9046
    
  10
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

Joined: Jul 22, 2000
Posts: 9046
    
  10
Perhaps it would be better if you had three methods rather than three classes.
tom brownlee
Greenhorn

Joined: Aug 14, 2001
Posts: 28
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

Joined: Feb 18, 2002
Posts: 26
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

Joined: Feb 18, 2002
Posts: 26
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 ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why wont this run