Advertisement
Guest User

nigga

a guest
May 19th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package Java_core;
  7.  
  8. import java.io.*;
  9.  
  10. /**
  11. *
  12. * @author Tri
  13. */
  14. public class Array {
  15. static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  16. public static void main(String[] args) throws IOException {
  17. int a[]= new int[100];
  18.  
  19. System.out.print("Enter n: ");
  20. int n = Integer.parseInt(in.readLine());
  21.  
  22. inputArray(a, n);
  23. showArray(a, n);
  24. showEven(a, n);
  25. showMain(a, n);
  26. prmSum(a, n);
  27. max(a, n);
  28.  
  29. sort(a, n);
  30. minmod30(a, n);
  31.  
  32. showArray(a, n);
  33. show3(a, n);
  34.  
  35.  
  36.  
  37. //Nhap mang so nguyen n phan tu
  38. //Hien cac phan tu chan
  39. //Co bao nhieu phan tu chinh phuong
  40. //Tinh tong cac phan tu la so nguyen to
  41. //Tim gia tri lon nhat trong mang
  42. //Tim gia tri nho nhat chia het cho 3
  43. //Sap xep mang tang dan
  44. //Sap xep mang giam dan cac phan tu tan cung la 3
  45.  
  46. }
  47. //FUNCTIONS
  48. static void inputArray(int a[], int n) throws IOException
  49. {
  50. System.out.println("Input the array a["+n+"]");
  51. for(int i=0; i<n; i++)
  52. {
  53. System.out.print("a["+ i +"]=");
  54. a[i]= Integer.parseInt(in.readLine());
  55. }
  56. System.out.println("");
  57. }
  58.  
  59. static void showArray(int a[], int n)
  60. {
  61. System.out.print("The full array: ");
  62. for(int i=0; i < n; i++)
  63. {
  64. System.out.print(+a[i]+" ");
  65. }
  66. System.out.println("");
  67. }
  68.  
  69. static void showEven(int a[], int n)
  70. {
  71. System.out.print("Even value(s) in the array: ");
  72. for(int i=0; i<n; i++)
  73. {
  74. if(a[i]%2==0) System.out.print(+a[i]+" ");
  75. }
  76. System.out.println("");
  77. }
  78.  
  79. static void showMain(int a[], int n)
  80. {
  81. int cnt=0;
  82. // System.out.print("Main number(s) in the array: ");
  83. for(int i=0; i<n; i++)
  84. {
  85. if(a[i]%Math.sqrt(a[i])==0) cnt++;
  86. }
  87. System.out.println("There are "+cnt+" main number(s) in the array");
  88. }
  89.  
  90. static boolean isPrm(int n)
  91. {
  92. boolean prm=true;
  93. if(n<2)return false;
  94. else
  95. {
  96. for(int i=2; i<n; i++)
  97. {
  98. if(n%i==0) return false;
  99. }
  100. return true;
  101. }
  102. }
  103.  
  104. static void prmSum(int a[], int n)
  105. {
  106. System.out.print("The sum off all prime numbers: ");
  107. int sum = 0;
  108. for(int i=0; i<n; i++)
  109. {
  110. if(isPrm(a[i])==true) sum+=a[i];
  111. }
  112. System.out.println(+sum);
  113. }
  114.  
  115. static void max(int a[], int n)
  116. {
  117. System.out.print("The greatest value in the array: ");
  118. int max=a[0];
  119. for(int i=0; i<n; i++)
  120. {
  121. if(a[i+1]>a[i]) max=a[i+1];
  122. }
  123. System.out.println(+max);
  124. }
  125.  
  126. static void minmod30(int a[], int n)
  127. {
  128. System.out.print("The smallest value that mod 3 equal to 0: ");
  129. for(int i=0; i<n; i++)
  130. {
  131. if(a[i]%3==0)
  132. {
  133. System.out.println(+a[i]);
  134. break;
  135. }
  136. }
  137. System.out.println("");
  138. }
  139.  
  140. static void sort(int a[], int n)
  141. {
  142. for(int i=0; i<n; i++)
  143. {
  144. for(int j=i+1; j<n; j++)
  145. {
  146. if(a[i] > a[j])
  147. {
  148. int temp = a[i];
  149. a[i] = a[j];
  150. a[j] = temp;
  151. }
  152. }
  153. }
  154. }
  155.  
  156. static void show3(int a[], int n)
  157. {
  158. System.out.print("The integers end with 3 in the array sorted descendingly: ");
  159. for(int i=n-1; i>=0; i--)
  160. {
  161.  
  162. }
  163. System.out.println("");
  164. }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement