0

If I were to run my code using java example hello 3 the output would be hello 3

However, if I want to run java example hello world 3 the output would be hello world not hello world 3

How would I fix this?

public static void main(String[] args){
        String t = args[1];
        int s = Integer.parseInt(args[0]);
        System.out.println(t)
        System.out.println(s)
thokuest
  • 5,800
  • 24
  • 36
  • 1
    have you actually run your program on those inputs with those results? The code you've posted doesn't compile. – tgdavies Mar 03 '21 at 05:20

1 Answers1

1

Taken from this answer: https://stackoverflow.com/a/17619865/6590339

You can use quotes when you want an argument to have a space in it:

$java example "hello 3"

  • it looks like this method doesn't include spaces in the output e.g.$java example "hello 3" returns "hello3" – h4rrison-b Mar 02 '21 at 23:10
  • I think there are some other issues in your method. If, you only care about the first argument, then I would just have `String t = args[0]` and `System.out.println(t)`. There is no need to use `Integer.parseInt` if you are just printing to the command line – SharkWithLasers Mar 02 '21 at 23:23