

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
import java.util.Scanner; class Division { public static void main(String[] args) { int a, b, result;. Scanner input = new Scanner(System.in);.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


import java.util.Scanner;
class Division {
public static void main(String[] args) {
int a, b, result;
Scanner input = new Scanner(System.in);
System.out.println("Input two integers");
a = input.nextInt();
b = input.nextInt();
// try block
try {
result = a / b;
System.out.println("Result = " + result);
}
// catch block
catch (ArithmeticException e) {
System.out.println("Exception caught: Division by zero.");
}
}
}
public class Triangle {
private int side1; private int side2; private int side3;
public Triangle(int side1, int side2, int side3)
{ if (side1 <= 0 || side2 <= 0 || side3 <= 0) throw new IllegalArgumentException(
"Sides can only be positive numbers");
this.side1 = side1; this.side2 = side2; this.side3 = side3;
}
public int getSide1() { return side1;
}
public void setSide1(int side1) { this.side1 = side1;
public int getSide2() { return side2;
}
public void setSide2(int side2) { this.side2 = side2;
}
public int getSide3() { return side3;