I just switch from BlueJ IDE to presently using the Eclipse IDE. I think it is much better. I am just starting to learn how to program in Java, reading 'Osborne Teach Yourself JAVA'. Now to my question. For some reason, probably not programming enough yet, I am not understanding what to do when I run my program and get this error message:
Will someone please give me an example, by showing me the rest of the program coding, I am leaving out as it pertains to the program in this thread? I tried writing code both ways below. I still am not programming correctly to get the program example I've submitting in this thread to give me output without the error message. The first program coding is how the book illustrate. The second example is my coding attempt to run the program without getting the error message.
/**
* Write an application that accepts two command-line arguments.
* Convert these to double values and divide the first number by
* the second number. Use an if-else statement to prevent division
* by zero from occurring.
*
*
*/
I also tried this program coding method, and got the following message:
/**
* Write an application that accepts two command-line arguments.
* Convert these to double values and divide the first number by
* the second number. Use an if-else statement to prevent division
* by zero from occurring.
*
*
*/
HTML:
'Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at ZeroDivide.main(ZeroDivide.java:12)'
Will someone please give me an example, by showing me the rest of the program coding, I am leaving out as it pertains to the program in this thread? I tried writing code both ways below. I still am not programming correctly to get the program example I've submitting in this thread to give me output without the error message. The first program coding is how the book illustrate. The second example is my coding attempt to run the program without getting the error message.
/**
* Write an application that accepts two command-line arguments.
* Convert these to double values and divide the first number by
* the second number. Use an if-else statement to prevent division
* by zero from occurring.
*
*
*/
HTML:
public class ZeroDivide {
public static void main(String args[]){
double d1 = Double.valueOf(args[0]).doubleValue();
double d2 = Double.valueOf(args[1]).doubleValue();
if(d2 == 0) System.out.print("Cannot divide by zero");
else System.out.print("Answer is:" + d1/d2);
}
}
I also tried this program coding method, and got the following message:
/**
* Write an application that accepts two command-line arguments.
* Convert these to double values and divide the first number by
* the second number. Use an if-else statement to prevent division
* by zero from occurring.
*
*
*/
HTML:
public class ZeroDivide {
public static void main(String args[]){
double d1 = Double.valueOf(args[0]).doubleValue();
double d2 = Double.valueOf(args[1]).doubleValue();
if(d2 == 0){ System.out.print("Cannot divide by zero");
}else{ System.out.print("Answer is:" + d1/d2);
}
}
}
HTML:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at ZeroDivide.main(ZeroDivide.java:12)