Results 1 to 5 of 5
Thread: Program
- 08-17-2009, 10:56 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 10
- Rep Power
- 0
Program
Hi guys
I was wondering if somebody could help me with this. The question I have been asked to do is:
Write a Java program which prints a string a multiple number of times, where the string and the multiple are supplied at the command line. For example, invoking java dog 3 should result in dogdogdog being printed.
What I have at the moment is:
class question1c
{
public static void main(String[] args)
{
String word = args[0];
int amount = Integer.parseInt(args[1]);
for (int i = 0 ; i < amount ; i++ )
{
System.out.print(word);
}
}
}
However this does not fully cover the question because in order to run it I would have to enter "java Question1c dog 3" which is different to what is being asked. Is there any way to complete this question? I tried putting class args[0] but that doesn't work.
Any help would be greatly appreciated.
Thanks
- 08-17-2009, 10:59 PM #2
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
Yours is the way to do it. You cant invoke a java program without the class name. This is the answer, and if your teacher tells you otherwise, ask him how its possible, because I'm darn sure its not.
If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
- 08-18-2009, 02:38 PM #3
Member
- Join Date
- Aug 2009
- Posts
- 10
- Rep Power
- 0
Hi thanks! I've emailed my lecturer but I dont know if he will reply! I thought it was just me! Ill let you know if he comes up with a strange solution!!
Thanks!
- 08-18-2009, 04:10 PM #4
Member
- Join Date
- Aug 2009
- Posts
- 10
- Rep Power
- 0
Hi Singing Boyo
Just heard back that the question was written wrong! And that was in a past paper! Way to throw you off!!
Thanks for your help!!
- 08-18-2009, 05:02 PM #5
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
Similar Threads
-
Execute A program from a Program!
By Moncleared in forum Advanced JavaReplies: 2Last Post: 02-22-2009, 04:17 PM -
Executing a program within a program
By gibsonrocker800 in forum New To JavaReplies: 5Last Post: 05-12-2008, 08:24 AM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks