Quantcast

Maximum PC

It is currently Thu Jul 31, 2014 12:12 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Echo command
PostPosted: Mon Oct 18, 2004 9:23 am 
Willamette
Willamette
User avatar

Joined: Mon Sep 13, 2004 11:38 am
Posts: 1258
Location: config t
I know a little C and since Java is kinda like C I am trying to start learnig it.

One of my assignements for my first class is telling me to create a unix style echo command, does this look right? It's not working! Anything I am doing wrong?

It's not printing its arguments:

public class echo {
public static void main {{string argv[]) {
for(int i=0; i < argv.length; i++)
System.out.print(argv[i] + " ");
System.out.print("\n");
System.exit(0);
}
}

//Yeah I write purdy code I know :P


Top
  Profile  
 
 Post subject:
PostPosted: Mon Oct 18, 2004 9:40 am 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24222
Location: Granite Heaven
Code:
  for(int i=0; i < argv.length; i++)
System.out.print(argv[i] + " ");


What happens if argv.length = 0?

Try inserting this line just ahead of that one:
Code:
System.out.print("Arguments in argv: " + argv.length + "\n");


Top
  Profile  
 
 Post subject:
PostPosted: Mon Oct 18, 2004 11:12 am 
Willamette
Willamette
User avatar

Joined: Mon Sep 13, 2004 11:38 am
Posts: 1258
Location: config t
It worked!

Thankee thankee!


Top
  Profile  
 
 Post subject:
PostPosted: Mon Oct 18, 2004 2:03 pm 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24222
Location: Granite Heaven
Glad to help. :)


Top
  Profile  
 
 Post subject:
PostPosted: Fri Oct 22, 2004 2:26 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
You shouldn't use argv in Java programming. Gives the impression that it means the same thing as in C. Also, please use the bbcode 'code' tag in the future! Like so....

Code:
import java.util.*;

class Echo {
    public static void main (String[] args) {
        System.out.println( Arrays.asList(args).toString().replaceAll("[\\[|\\]]","") );
        System.exit(0);
    }
}


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group