Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (1)
- import java.io.IOException;
- import java.security.InvalidParameterException;
- public class TestException {
- public static void main(String[] args) throws IOException {
- TestException.throwException(5);
- TestException.throwException(-5);
- }
- public static void throwException(int n) throws InvalidParameterException, ArithmeticException, IOException {
- Integer.parseInt("2");
- if (n <= 0) {
- throw new InvalidParameterException("Parameter shoud be grater than 0");
- }
- if (n > 100) {
- throw new IOException("Parameter must be smaller than 100");
- }
- System.out.println(n * n);
- }
- }
- 2(a) & (b)
- public class TestIO {
- public static void main(String[] args){
- try {
- FileReader fr = new FileReader("olympic.txt");
- BufferedReader br = new BufferedReader(fr);
- PrintWriter pw = new PrintWriter("processed.txt");
- String s =br.readLine();
- int value=0;
- while(s!=null){
- String[] array = s.split(" ");
- for(int i=1;i<=3;i++){
- value+= Integer.parseInt(array[i]);
- System.out.println("Total value is : "+value);
- }
- pw.println(s+" "+"Total :"+value);
- value =0;
- System.out.println(s);
- s =br.readLine();
- }
- fr.close();
- pw.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment