Liebe Mitlesende,
Ich habe ein Programm, dass ein array von Nummern mit HashMaps darstellen soll. Es hat funktioniert, als alle Zahlen Ganzzahlen waren. Beim Ändern der Zahlen in Kommazahlen geht es nicht mehr. Als Fehlermeldung bekomme ich einen outOfBoundsError 0 angezeigt in der Zeile
Double minVal = Double.parseDouble(args[0]).
Kann mir jemand helfen?
Vielen Dank und Grüße
Ich habe ein Programm, dass ein array von Nummern mit HashMaps darstellen soll. Es hat funktioniert, als alle Zahlen Ganzzahlen waren. Beim Ändern der Zahlen in Kommazahlen geht es nicht mehr. Als Fehlermeldung bekomme ich einen outOfBoundsError 0 angezeigt in der Zeile
Double minVal = Double.parseDouble(args[0]).
Kann mir jemand helfen?
Java:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* A HashMap is an array with lots of numbers,
* and the key lets you identify which value in that array or map of values to use.
*/
public class Counter3
{
private HashMap<Double, Double> mapping;
public Counter3()
{
this.mapping = new HashMap<>();
}
public void update(Double key)
{
Double currentValue = this.valueOf(key);
this.mapping.put(key, currentValue + 1);
}
public Double valueOf(Double key)
{
Double value = this.mapping.get(key);
if(value == null)
{
return 0.0;
}
return value;
}
public double size()
{
return this.mapping.size();
}
public ArrayList allKeysAndValues()
{
ArrayList<Double> keys = new ArrayList<>();
ArrayList<Double> values = new ArrayList<>();
for(Map.Entry<Double, Double> entry: this.mapping.entrySet())
{
keys.add(entry.getKey());
values.add(entry.getValue());
}
ArrayList<List<Double>> out = new ArrayList<>();
out.add(keys);
out.add(values);
return out;
}
public void printAll()
{
System.out.println("keys" + "," + "counts");
for(Map.Entry<Double, Double> entry: this.mapping.entrySet())
{
System.out.println(entry.getKey() + "," + entry.getValue());
}
}
public static void main(String[] args)
{
Double minVal = Double.parseDouble(args[0]);//error points to this line
Double maxVal = Double.parseDouble(args[1]);
Counter3 count = new Counter3();// changed Counter to Counter3
double n = count.size();//was int, changed to double - where do you use n?
for(double a = minVal; a <= maxVal; a += 1.0)
{
for(double b = minVal; b <= maxVal; b += 1.0)
{
for(double c = minVal; c <= maxVal; c += 1.0)
{
for(double d = minVal; d <= maxVal; d += 1.0)
{
count.update((Double)(a*c-b*d));
}
}
}
}
count.printAll();
}
}