Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Tìm phần tử lẻ đầu tiên của mảng
- * Không dùng break
- */
- public class OddArr {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int n;
- boolean check = true;
- System.out.print("n = ");
- n = in.nextInt();
- while(n < 1) {
- System.out.print("Nhap lai n: ");
- n = in.nextInt();
- }
- int[] numbers = new int[n];
- for (int i = 0; i < n; ++i) {
- System.out.print("nhap vao phan tu thu " + i + ": ");
- numbers[i] = in.nextInt();
- }
- for(int i = 0; i < n; ++i) {
- if(numbers[i] % 2 != 0 && check) {
- System.out.println("\nSo le dau tien cua mang la: " + numbers[i]);
- check = false;
- }
- }
- if (check) {
- System.out.println("\nKhong co so le trong mang");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement