The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Java2
By Guest on 17th December 2018 05:24:25 AM | Syntax: TEXT | Views: 1



New paste | Download | Show/Hide line no. | Copy text to clipboard
  1. areacircleinterface
  2.  
  3. import java.io.*;
  4. import java.lang.*;
  5. interface circle
  6. { float r,ar;
  7. void get()throws IOException
  8. { BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
  9. r=Float.parseFloat(br.readLine());
  10. ar=pi*r*r;
  11. }
  12. void display()
  13. {
  14.  
  15. System.out.println("area of circle is "+ar);
  16. }
  17. }
  18. class sphere implements circle
  19. {
  20. float r,ar;
  21. void getdata()throws IOException
  22. { BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
  23. r=Float.parseFloat(br.readLine());
  24. ar=4*pi*r*r;
  25. }
  26. void print()
  27. {
  28.  
  29. System.out.println("area of sphere is "+ar);
  30. }}
  31. class Areamain
  32. {public static void main(String args[])throws IOException
  33. {
  34. sphere s=new sphere();
  35. s.get();
  36. s.display();
  37. s.getdata();
  38. s.print();
  39. }}
  40.  
  41.  
  42. greatest
  43.  
  44.  
  45. import java.io.*;
  46. import java.lang.*;
  47. class great
  48. {
  49. int a,b;
  50. void get() throws IOException
  51. {
  52. BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
  53. System.out.println("enter two numbers: ");
  54. a=Integer.parseInt(br.readLine());
  55. b=Integer.parseInt(br.readLine());
  56. }
  57. void greatest()
  58. {
  59. if (a>b)
  60. System.out.println("greatest is : "+a);
  61. else if(b>a)
  62. System.out.println("greatest is : "+b);
  63. else
  64. System.out.println("equal");
  65. }
  66. }
  67. class three extends great
  68. {
  69. int a,b,c;
  70. void getnumber() throws IOException
  71. {
  72.  
  73. BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
  74. System.out.println("enter three numbers: ");
  75. a=Integer.parseInt(br.readLine());
  76. b=Integer.parseInt(br.readLine());
  77. c=Integer.parseInt(br.readLine());
  78. }
  79. void greatest()
  80. {
  81. super.greatest();
  82. if (a>=b&&a>=c)
  83. System.out.println("greatest is : "+a);
  84. else if(b>=a&&b>=c)
  85. System.out.println("greatest is : "+b);
  86. else
  87. System.out.println("greatest is : "+c);
  88. }
  89. }
  90. class greatmain
  91. {
  92. public static void main(String args[])throws IOException
  93. {
  94.  three t=new three();
  95. t.get();
  96. t.getnumber();
  97.  
  98. t.greatest();
  99. }}
  100.  
  101.  
  102.  
  103. thread
  104.  
  105.  
  106. import java.io.*;
  107. class even extends Thread
  108. { int a1;
  109. even(int a)
  110. {a1=a;}
  111. public void run()
  112. { int i=0;
  113. for(i=0;i<a1;++i)
  114. {if(i%2==0)
  115. System.out.println(i);
  116. }
  117. System.out.println("are even");}
  118. }
  119. class odd extends Thread
  120. { int a2;
  121. odd(int a)
  122. {a2=a;
  123. }
  124. public void run()
  125. {int i=0;
  126.  for(i=0;i<a2;++i)
  127. {if(i%2!=0)
  128. System.out.println(i);
  129. }
  130. System.out.println("are odd");}
  131. }
  132. class mainthread
  133. {
  134. public static void main(String args[])throws IOException
  135. { int n;
  136. BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  137. System.out.print("enter the limit");
  138. n=Integer.parseInt(br.readLine());
  139. even e=new even(n);
  140. odd o=new odd(n);
  141. e.start();
  142. o.start();
  143. }
  144. }
  145.  
  146.  
  147. throw
  148.  
  149.  
  150. import java.io.*;
  151. import java.lang.Throwable;
  152. class arithmain
  153. {
  154. public static void main(String args[])throws IOException
  155. {
  156. int a,b;
  157. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  158. System.out.println("Enter numbers to be divided");
  159. a=Integer.parseInt(br.readLine());
  160. b=Integer.parseInt(br.readLine());
  161. try
  162. {
  163. System.out.print(a/b);
  164. if(b==0)
  165. throw new ArithmeticException();}
  166. catch(ArithmeticException e)
  167. {
  168. System.out.println("divide by zero produces arithmetic exception");
  169. }
  170. }}



  • Recent Pastes