Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2003
    Posts
    2

    Unanswered: Java assignment fer school

    Well im new at this. Never programmed in Java before, so i dont know much.
    For school I had to make a easy program, but its not easy if they dont tell you how to program and instead keep blabbering about ints and doubles.

    So this is my first program:

    public class Opgave1 {

    public static void main(String[] args) {
    double Fahrenheit = Double.parseDouble(args[0]);
    double Celsius = 5.0 / 9.0 * ( Fahrenheit - 32 );
    System.out.println("Het aantal" + Celsius);

    }

    }

    I was supposed to make a Fahrenheit to Celcius converter. So this is what ive made so far. The compiler says its good, but when i execute it it says :

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
    at Opgave1.main(Opgave1.java:4)

    Because i'm new I dont know what it means, can somebody help me out here? I dont expect you to make the assignment for me or something, I just need some enlightment. Can please say whats wrong with this?
    Please dont say anything complicated, because im supposed to make this program out of basic java commands.
    Thx in advance!

    Greetingz ChroNoZz

  2. #2
    Join Date
    Sep 2002
    Posts
    456

    Re: Java assignment fer school

    While running the program, are you passing any parameter on the command line? If not thats your problem then. In your code, the line:

    double Fahrenheit = Double.parseDouble(args[0]);

    Takes the parameter you passed as args[0] and parse it to double if you don't pass any parameter to the program the array args[] is empty thus the error!!!

    dollar

    Originally posted by ChroNoZz
    Well im new at this. Never programmed in Java before, so i dont know much.
    For school I had to make a easy program, but its not easy if they dont tell you how to program and instead keep blabbering about ints and doubles.

    So this is my first program:

    public class Opgave1 {

    public static void main(String[] args) {
    double Fahrenheit = Double.parseDouble(args[0]);
    double Celsius = 5.0 / 9.0 * ( Fahrenheit - 32 );
    System.out.println("Het aantal" + Celsius);

    }

    }

    I was supposed to make a Fahrenheit to Celcius converter. So this is what ive made so far. The compiler says its good, but when i execute it it says :

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
    at Opgave1.main(Opgave1.java:4)

    Because i'm new I dont know what it means, can somebody help me out here? I dont expect you to make the assignment for me or something, I just need some enlightment. Can please say whats wrong with this?
    Please dont say anything complicated, because im supposed to make this program out of basic java commands.
    Thx in advance!

    Greetingz ChroNoZz

  3. #3
    Join Date
    Jan 2003
    Posts
    2

    Smile Re: Java assignment fer school

    Yeah thx m8, I already found that out. But thx for the confirmation!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •