Input In Java- How does it work?

Posted by Nir Avnon on Stack Overflow See other posts from Stack Overflow or by Nir Avnon
Published on 2011-03-05T23:08:49Z Indexed on 2011/03/05 23:24 UTC
Read the original article Hit count: 173

Filed under:

Hey guys, with a lot of help from you i was managed to write this nice code (I'm new in it, so kind of exciting.. :) ) And still I have not understand how can I input this code. first of all, I get an this error in the console line (I'm using Eclipse): Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at NumberConverter.main(NumberConverter.java:5). What does that mean?

I just want to chack whether it works, and I can't call the function/program any how. I used to call in an "old fashion way", like in scheme, to the function that I wrote and see if something happens. How does it work in java? Do we call the program itself? function? what and where do we write? -I want to chack if it works, doesn't matter how, and I'll be glad to know how can I plugin input. Thank you so much!

public class NumberConverter{
 public static void main(String[] args) {
       int i = Integer.parseInt(args[0]);
       toBinary(i);
       toOctal(i);
       toHex(i);
   }

   public static void toBinary(int int1){
       System.out.println(int1 + " in binary is");
       System.out.println(Integer.toBinaryString(int1));
   }
   public static void toOctal(int int1){
       System.out.println(int1 + " in octal is");
       System.out.println(Integer.toOctalString(int1));
   }

   public static void toHex(int int1){
       System.out.println(int1 + " in hex is");
       System.out.println(Integer.toHexString(int1));
   }

}

© Stack Overflow or respective owner

Related posts about java