Guest User

Untitled

a guest
Jun 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. package com.batch5.day1.q1;
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6.  
  7. public class Fibonacci
  8. {
  9. public static void main(String st[])
  10. {
  11. float sum=0;
  12. int number1=1;
  13. int number2=1;
  14. int number3;
  15. sum=number1+number2;
  16. Scanner sc=new Scanner(System.in);
  17. System.out.println("Enter size of fibonacci");
  18. int size=sc.nextInt();
  19. System.out.print(number1+" "+number2);
  20.  
  21. for(int i=2;i<size;i++)
  22. {
  23. number3=number1+number2;
  24. sum=sum+number3;
  25. System.out.print(" "+number3);
  26. number1=number2;
  27. number2=number3;
  28. }
  29. sc.close();
  30. System.out.println();
  31.  
  32. System.out.println("The average is: "+(sum/20));
  33. }
  34. }
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. 1-2
  44.  
  45.  
  46.  
  47.  
  48. package com.batch5.day1.q2;
  49.  
  50. public class TimeTable
  51. {
  52.  
  53. void multiply()
  54. {
  55. System.out.println("*|1 2 3 4 5 6 7 8 9");
  56. System.out.println("--------------------------");
  57. for(int i=1;i<=9;i++)
  58. {
  59. System.out.print(i+"|");
  60. for(int j=1;j<=9;j++)
  61.  
  62. {
  63. System.out.print(i*j+" ");
  64. }
  65. System.out.println();
  66.  
  67. }
  68. }
  69.  
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. 1-3
  88.  
  89.  
  90.  
  91. package com.batch5.day1.q3;
  92.  
  93. import java.util.Scanner;
  94.  
  95. public class GradeAverage {
  96. public static void main(String st[])
  97. {
  98.  
  99. Scanner sc=new Scanner(System.in);
  100. int noOfStudents;
  101. float sumOfGrade=0;
  102. System.out.print("Enter the number of students: ");
  103. noOfStudents=sc.nextInt();
  104. System.out.println();
  105.  
  106. int grades[]=new int[noOfStudents+1];
  107.  
  108. for(int i=1;i<=noOfStudents;i++)
  109. {
  110. System.out.print("Enter the grade of student "+i+": ");
  111. grades[i]=sc.nextInt();
  112. System.out.println();
  113.  
  114. if(grades[i]<0||grades[i]>100)
  115. {
  116. System.out.println("Enter valid input");
  117. System.out.println("Enter the grade of student "+i+": ");
  118. grades[i]=sc.nextInt();
  119. sumOfGrade+=grades[i];
  120. }
  121.  
  122. else
  123. {
  124. sumOfGrade+=grades[i];
  125. }
  126.  
  127. }
  128. sc.close();
  129. System.out.println("The average is: "+(sumOfGrade/noOfStudents));
  130.  
  131.  
  132. }
  133.  
  134. }
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148. 1-4
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. package com.batch5.day1.q4;
  159.  
  160. import java.util.Scanner;
  161.  
  162. public class ArrayCopy {
  163.  
  164. public static int[] copyOf(int[] array)
  165. {
  166. return array;
  167. }
  168.  
  169. public static void main(String st[])
  170. {
  171.  
  172. int arr[]=new int[10];
  173. Scanner sc=new Scanner(System.in);
  174. System.out.println("Enter size of array(max 10)");
  175. int size=sc.nextInt();
  176. System.out.println("Enter the elements)");
  177. for(int i=0;i<size;i++)
  178. {
  179. arr[i]=sc.nextInt();
  180. }
  181. int copy[]=copyOf(arr);
  182.  
  183. System.out.println("Copied Array: ");
  184.  
  185. for(int i=0;i<size;i++)
  186. {
  187. System.out.println(copy[i]);
  188. }
  189. sc.close();
  190. }
  191.  
  192. }
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205. 1-5
  206.  
  207.  
  208.  
  209.  
  210.  
  211. package com.batch5.day1.q5;
  212.  
  213. public class Pattern {
  214. public static void main(String st[])
  215. {
  216. for(int i=1;i<=8;i++)
  217. {
  218. for(int j=1;j<=i;j++)
  219. {
  220. System.out.print(j);
  221. }
  222. System.out.println();
  223. }
  224. }
  225.  
  226. }
Add Comment
Please, Sign In to add comment