Siehe:public static int parseInt(String s)
throws NumberFormatException
Was meinst du damit? Ist dir nun das Prinzip klar oder nicht ? Weisst du wofür finally da ist, welche Exceptions man nicht catchen muss, was throws macht etc. ?wie man das überhaupt programmiert
Ist vielleicht ein bisschen "schwammig" formuliert - schließlich könnte dann auch einer meinen er müsste von "Throwable" oder "Error", "RuntimeException" etc. ableiten.comp89 hat gesagt.:indem die klasse von einer exception erbt
Warum das? Von FW geblockt?amicelli hat gesagt.:Das API hab ich gefunden, aber kann nicht drauf zugreifen. Gibts da nicht noch ne andere Variante?
import algds.IOUtils;
public class Dreieck {
Dreieck() {
int seitea=IOUtils.readInt();
int seiteb=IOUtils.readInt();
int seitec=IOUtils.readInt();
Flächeninhalt(seitea,seiteb,seitec);
Umfang(seitea,seiteb,seitec);
}
double Flächeninhalt(int a,int b,int c){
...
}
int Umfang(int a,int b,int c){
...
}
public static void main(String[] args) {
new Dreieck();
}
}
import Exception.InvalidTriException;
import algds.IOUtils;
public class Dreieck {
Dreieck() throws InvalidTriException{
int seitea=IOUtils.readInt();
int seiteb=IOUtils.readInt();
int seitec=IOUtils.readInt();
boolean pos=true;
if(seitea+seiteb <= seitec)pos=false;
if(seiteb+seitec <= seitea)pos=false;
if(seitea+seitec <= seiteb)pos=false;
if (pos!=true)
throw new InvalidTriException("Es wird kein Dreieck aufgespannt");
flächeninhalt(seitea,seiteb,seitec);
umfang(seitea,seiteb,seitec);
}
double flächeninhalt(int a,int b,int c){
...
}
int umfang(int a,int b,int c){
...
}
public static void main(String[] args) {
new Dreieck();
}
}
package Exception;
public class InvalidTriException extends RuntimeException{
public InvalidTriException(String err){
super(err);
}
}
amicelli hat gesagt.:naja und das hab ich so gefunden, weis nur nicht was das "super" bedeutet:
Code:package Exception; public class InvalidTriException extends RuntimeException{ public InvalidTriException(String err){ super(err); } }
tja und try und catch wurden da überhaupt nicht verwendet, was ich auch schon wieder nicht kapiere
public class InvalidTriException extends Exception {
public InvalidTriException() {
super();
}
public InvalidTriException(String err) {
super(err);
}
}
try {
new Dreieck();
} catch(InvalidTriException ite) {
System.err.println(ite.getMessage());
ite.printStackTrace();
}
amicelli hat gesagt.:Code:if (pos!=true) throw new InvalidTriException("Es wird kein Dreieck aufgespannt");
if(!pos)
...