Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. /**
  2. * Tìm phần tử lẻ đầu tiên của mảng
  3. * Không dùng break
  4. */
  5. public class OddArr {
  6.  
  7. public static void main(String[] args) {
  8. Scanner in = new Scanner(System.in);
  9. int n;
  10. boolean check = true;
  11.  
  12. System.out.print("n = ");
  13. n = in.nextInt();
  14.  
  15. while(n < 1) {
  16. System.out.print("Nhap lai n: ");
  17. n = in.nextInt();
  18. }
  19.  
  20. int[] numbers = new int[n];
  21.  
  22. for (int i = 0; i < n; ++i) {
  23. System.out.print("nhap vao phan tu thu " + i + ": ");
  24. numbers[i] = in.nextInt();
  25. }
  26.  
  27. for(int i = 0; i < n; ++i) {
  28. if(numbers[i] % 2 != 0 && check) {
  29. System.out.println("\nSo le dau tien cua mang la: " + numbers[i]);
  30. check = false;
  31. }
  32. }
  33.  
  34. if (check) {
  35. System.out.println("\nKhong co so le trong mang");
  36. }
  37.  
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement