Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. class Main {
  2. public static void main(String[] args) {
  3. System.out.println("Hello World! \n It's been nice knowing you. \n Goodbye World ");
  4. }
  5. }
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12. class Main {
  13. public static void main(String[] args) {
  14. System.out.println("==================================");
  15. System.out.println("= Student Information =");
  16. System.out.println("==================================");
  17. System.out.println("= Name : ARDP Ranasignhe =");
  18. System.out.println("= Reg No : DIS\t08\tM4\t1234 =");
  19. System.out.println("= Address : Malabe =");
  20. System.out.println("==================================");
  21.  
  22.  
  23. }
  24. }
  25.  
  26.  
  27.  
  28.  
  29. class Main {
  30. public static void main(String[] args) {
  31. int age=20;
  32. if (age > 18){
  33. System.out.print("Adult");
  34. }
  35. else{
  36. System.out.print("Child");
  37. }
  38.  
  39. }
  40. }
  41.  
  42.  
  43.  
  44. import java.util.Scanner;
  45. class Main {
  46. public static void main(String[] args) {
  47. Scanner scanner= new Scanner(System.in);
  48. System.out.print("Value of the day : ");
  49. int val=scanner.nextInt();
  50. switch (val) {
  51. case 1:
  52. System.out.println("Day of the week : Monday");
  53. break;
  54. case 2:
  55. System.out.println("Day of the week : Tuesday");
  56. break;
  57. case 3:
  58. System.out.println("Day of the week : Wednesday");
  59. break;
  60. case 4:
  61. System.out.println("Day of the week : Thursday");
  62. break;
  63. case 5:
  64. System.out.println("Day of the week : Friday");
  65. break;
  66. case 6:
  67. System.out.println("Day of the week : Saturday");
  68. break;
  69. case 7:
  70. System.out.println("Day of the week : Sunday");
  71. break;
  72. }
  73. System.out.print("Good Bye!");
  74. }
  75. }
  76.  
  77.  
  78.  
  79. class Main {
  80. public static void main(String[] args) {
  81. int m=1,o=1;
  82. while (o<=5){
  83. m=0;
  84. while (m<=5)
  85. {
  86. System.out.print("*");
  87. m++;
  88. }
  89. System.out.println();
  90. o++;
  91. }
  92. for (int i=0; i<5; i++) {
  93. for (int j=5-i; j>1; j--){
  94. System.out.print(" ");
  95. }
  96. for (int j=0; j<=i; j++ ){
  97. System.out.print("* ");
  98. }
  99. System.out.println();
  100. }
  101. }
  102.  
  103. }
  104.  
  105.  
  106.  
  107. class Main {
  108. public static void main(String[] args) {
  109.  
  110. int k = 10;
  111. for(int i = 0; i < 5; i++) {
  112. for(int j = 0; j < 5; j++) {
  113. System.out.print("* ");
  114. }
  115. for(int m = 1; m < k; m++) {
  116. System.out.print(" ");
  117. }
  118. k--;
  119. for(int n = 0; n <= i; n++) {
  120. System.out.print("* ");
  121. }
  122. System.out.println();
  123. }
  124. }
  125. }
  126.  
  127.  
  128. import java.util.Scanner;
  129. class Main {
  130. public static void main(String[] args) {
  131. int num1,num2;
  132. Scanner scanner=new Scanner (System.in);
  133. System.out.println("Enter two numbers");
  134. num1=scanner.nextInt();
  135. num2=scanner.nextInt();
  136. System.out.println("The Avergae of the two number is:- "+(num1+num2)/2);
  137.  
  138. }
  139. }
  140.  
  141.  
  142.  
  143.  
  144. lab 2
  145.  
  146.  
  147. class Main {
  148. public static void main(String[] args) {
  149. int miles = 26,yards = 385;
  150. double kilometers = 0;
  151.  
  152. // Write the expression to convert the given values to kilometers
  153. miles=miles+(1760*yards);
  154. kilometers=(miles*1.609);
  155. System.out.println("Number of kilometers are " + kilometers);
  156. }
  157. }
  158.  
  159.  
  160.  
  161. import java.util.Scanner;
  162. class Main {
  163. public static void main(String[] args) {
  164. String name,id,district;
  165. Scanner scanner=new Scanner(System.in);
  166. System.out.print("Enter the Student's First Name :- ");
  167. name=scanner.nextLine();
  168. System.out.print("Enter the Student's ID :- ");
  169. id=scanner.nextLine();
  170. System.out.print("Enter the Student's District :- ");
  171. district=scanner.nextLine();
  172. System.out.println("DitNo : "+name);
  173. System.out.println("Name: "+id);
  174. System.out.println("District : "+district);
  175.  
  176.  
  177.  
  178. }
  179. }
  180.  
  181.  
  182.  
  183. import java.util.Scanner;
  184. class Main {
  185. public static void main(String[] args) {
  186. int length, width, height;
  187. int volume = 0;
  188. Scanner scanner=new Scanner(System.in);
  189. //Take user inputs using Scanner class
  190. System.out.println("Enter the length of the cube:-");
  191. length=scanner.nextInt();
  192. System.out.println("Enter the width of the cube:-");
  193. width=scanner.nextInt();
  194. System.out.println("Enter the height of the cube:-");
  195. height=scanner.nextInt();
  196.  
  197.  
  198. //Calculate the volume of cube
  199. volume=length*width*height;
  200.  
  201. System.out.println("Volume of the cube : "+volume);
  202. }
  203. }
  204.  
  205.  
  206. import java.io.BufferedReader;
  207. import java.io.InputStreamReader;
  208. class Main {
  209. public static void main(String[] args) {
  210. int length, width, height;
  211. int volume = 0;
  212. String l,w,h;
  213.  
  214. //Take user inputs using InputStreamReader class or BufferedReader class
  215. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  216.  
  217. System.out.println("Enter the length of the cube:-");
  218. l = reader.readLine();
  219. length=Integer.parseInt(l);
  220.  
  221. System.out.println("Enter the width of the cube:-");
  222. w = reader.readLine();
  223. width=Integer.parseInt(w);
  224.  
  225. System.out.println("Enter the height of the cube:-");
  226. h = reader.readLine();
  227. height=Integer.parseInt(h);
  228.  
  229.  
  230. //Calculate the volume of cube
  231. volume=length*width*height;
  232.  
  233.  
  234. //Calculate the volume of cube
  235.  
  236. System.out.println("Volume of the cube : "+volume);
  237. }
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement