NB52053

Assignment_LAB_7

Aug 12th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. (1)
  2.  
  3. import java.io.IOException;
  4. import java.security.InvalidParameterException;
  5.  
  6. public class TestException {
  7.     public static void main(String[] args) throws IOException {
  8.  
  9.             TestException.throwException(5);
  10.             TestException.throwException(-5);
  11.     }
  12.  
  13.     public static void throwException(int n) throws InvalidParameterException, ArithmeticException, IOException {
  14.         Integer.parseInt("2");
  15.         if (n <= 0) {
  16.             throw new InvalidParameterException("Parameter shoud be grater than 0");
  17.         }
  18.         if (n > 100) {
  19.             throw new IOException("Parameter must be smaller than 100");
  20.         }
  21.         System.out.println(n * n);
  22.     }
  23. }
  24.  
  25.  
  26. 2(a) & (b)
  27. public class TestIO {
  28.    
  29.     public static void main(String[] args){
  30.         try {
  31.             FileReader fr = new FileReader("olympic.txt");
  32.             BufferedReader br = new BufferedReader(fr);
  33.             PrintWriter pw = new PrintWriter("processed.txt");
  34.             String s =br.readLine();
  35.            
  36.            
  37.             int value=0;
  38.            
  39.            
  40.             while(s!=null){
  41.                 String[] array = s.split(" ");
  42.                
  43.                
  44.                 for(int i=1;i<=3;i++){
  45.                      value+= Integer.parseInt(array[i]);
  46.                     System.out.println("Total value is : "+value);
  47.                 }
  48.                
  49.                 pw.println(s+"     "+"Total :"+value);
  50.                 value =0;
  51.                 System.out.println(s);
  52.                 s =br.readLine();
  53.             }
  54.            
  55.                 fr.close();
  56.             pw.close();
  57.         } catch (FileNotFoundException e) {
  58.            
  59.           e.printStackTrace();
  60.         } catch (IOException e) {
  61.             e.printStackTrace();
  62.             }
  63.         }
  64.   }
Add Comment
Please, Sign In to add comment