Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import java.io.*;
  2. class Interval {
  3.  
  4. private int linf,lsup,nrtestate,nrgasite;
  5.  
  6. public Interval(int inferior,int superior)
  7. {
  8. linf=inferior;
  9. lsup=superior;
  10. }
  11. public void testare(Double x)
  12. {
  13. nrtestate++;
  14. boolean istrue = ((x >=linf) && (x <= lsup));
  15. if(istrue) nrgasite++;
  16. }
  17. public String toString()
  18. {
  19. return "[" + linf + "," + lsup + "]";
  20. }
  21. }
  22.  
  23. class Main
  24. {
  25. public static void main(String arg[])
  26. {
  27. try
  28. {
  29. BufferedReader file = new BufferedReader
  30. (new InputStreamReader(new FileInputStream ("intervale.dat")));
  31. Integer nr_citit1,nr_citit2;
  32. String inf,sup;
  33. int nr=0;
  34. Interval[] obj = new Interval[100];
  35. while(( inf=file.readLine()) != null)
  36. {
  37. sup = file.readLine();
  38. obj[nr] = new Interval(Integer.parseInt(inf),Integer.parseInt(sup));
  39. System.out.print("\nIntervalul" + nr+ "=" + obj[nr]);
  40. nr++;
  41. }
  42. file.close();
  43. } catch(IOException e)
  44. {
  45. System.out.println("Error fisier!");
  46. System.exit(1);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement