prateeksharma

Lab_03_Work

Sep 3rd, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. Question5
  2.  
  3. package lab_03_Assignment_Work;
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class Ques5 {
  8. public static void main(String[] args) {
  9. int date;
  10. int month;
  11. int year;
  12. int r = 0;
  13. int m = 0;
  14. int y = 0;
  15. String s = "" ;
  16. Scanner k = new Scanner(System.in);
  17. System.out.print("date: ");
  18. date = k.nextInt();
  19. System.out.print("month: ");
  20. month = k.nextInt();
  21. System.out.print("year: ");
  22. year = k.nextInt();
  23. if(month == 1){m = 0;
  24. s = "January ";
  25. }
  26. else if(month == 2){m = 3;
  27. s = "February ";
  28. }
  29. else if(month == 3){m = 3;
  30. s = "March ";
  31. }
  32. else if(month == 4){m = 6;
  33. s = "April ";
  34. }
  35. else if(month == 5){m = 1;
  36. s = "May ";
  37. }
  38. else if(month == 6){m = 4;
  39. s = "June ";
  40. }
  41. else if(month == 7){m = 6;
  42. s = "July ";
  43. }
  44. else if(month == 8){m = 2;
  45. s = "August ";
  46. }
  47. else if(month == 9){m = 5;
  48. s = "September ";
  49. }
  50. else if(month == 10){m = 0;
  51. s = "October ";
  52. }
  53. else if(month == 11){m = 3;
  54. s = "November ";
  55. }
  56. else if(month == 12){m = 5;
  57. s = "December ";
  58. }
  59. if (1600 <= year && year >= 1699){y=6;}
  60. else if(1700 <= year && year >= 1799){y=4;}
  61. else if(1800 <= year && year >= 1899){y=2;}
  62. else if(1900 <= year && year >= 1999){y=0;}
  63. else if (2000 <= year && year >= 2099){y=6;}
  64. int re = year%100;
  65. r = re + (int)((re)/4) + date + m +y ;
  66. if (r>=7){
  67. r = r%7;
  68. }
  69. if (year%100 == 0){
  70. if (year%400 == 0 && (month == 1 || month == 2)){
  71. r = r - 1;
  72. }
  73. }
  74. else{
  75. if (year%4 == 0 && (month == 1 || m == 2)){
  76. r = r - 1;
  77. }
  78. }
  79. switch (r){
  80. case 1:
  81. System.out.println(date+"th "+ s + year + " was a Monday!");
  82. break;
  83. case 2:
  84. System.out.println(date+"th "+ s + year + " was a Tuesday!");
  85. break;
  86. case 3:
  87. System.out.println(date+"th "+ s + year + " was a Wednesday!");
  88. break;
  89. case 4:
  90. System.out.println(date+"th "+ s + year + " was a Thursday!");
  91. break;
  92. case 5:
  93. System.out.println(date+"th "+ s + year + " was a Friday!");
  94. break;
  95. case 6:
  96. System.out.println(date+"th "+ s + year + " was a Saturday!");
  97. break;
  98. case 0:
  99. System.out.println(date+"th "+ s + year + " was a Sunday!");
  100. break;
  101. }
  102.  
  103. }
  104. }
  105.  
  106.  
  107. Question1
  108.  
  109. package lab_03_Assignment_Work;
  110.  
  111. import java.util.Scanner;
  112.  
  113. public class Ques1 {
  114. public static void main(String[] args) {
  115. double s = 0.0;
  116. int n;
  117. Scanner scan = new Scanner(System.in);
  118. n = scan.nextInt();
  119. for (int i = 1; i <= n ; i++) {
  120. s = s + (1.0/i);
  121. }
  122. System.out.println( s );
  123.  
  124. }
  125. }
  126.  
  127.  
  128. Question2
  129.  
  130. package lab_03_Assignment_Work;
  131.  
  132. import java.util.Scanner;
  133.  
  134. public class Ques2 {
  135. public static void main(String[] args) {
  136. double no;
  137. double paise = 0.0;
  138. int rupee;
  139. Scanner k = new Scanner(System.in);
  140. no = k.nextDouble();
  141. rupee = (int)no;
  142. paise = 100*(no - rupee);
  143. System.out.println(rupee+" Rupees and "+(int)paise+" Paise");
  144.  
  145.  
  146. }
  147. }
  148.  
  149.  
  150. Question3
  151.  
  152. package lab_03_Assignment_Work;
  153.  
  154. import java.util.Scanner;
  155.  
  156. public class Ques3 {
  157. public static void main(String[] args) {
  158. double fahrenheit;
  159. double celcius;
  160. Scanner k = new Scanner(System.in);
  161. fahrenheit = k.nextDouble();
  162. celcius = (fahrenheit-32)/1.8;
  163. System.out.printf("%5.6f%n",celcius);
  164. }
  165. }
  166.  
  167.  
  168. pattern printing nhi ki h maine
Add Comment
Please, Sign In to add comment