Untitled

mail@pastecode.io avatar
unknown
plain_text
19 days ago
1.8 kB
13
Indexable
Never
//classevalone

import java.util.Scanner;

public class ClassEvalOne {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("N = ");
        int length = sc.nextInt();
        int[] array = new int[length];

        for (int i = 0; i < length; i++) {
            array[i] = sc.nextInt();
        }

        System.out.println("Original Array:");
        for (int i = 0; i < length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();

        for (int i = 0; i < length; i++) {
            if (array[i] > 0) {
                array[i] = 1;
            } else if (array[i] < 0) {
                array[i] = 0;
            }
        }


        System.out.println("After modifying:");
        for (int i = 0; i < length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();
    }
}


//classevaltwo

import java.util.Scanner;

public class ClassEvalTwo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("N = ");
        int length = sc.nextInt();
        int[] array = new int[length];

        for (int i = 0; i < length; i++) {
            System.out.print("Enter a number: ");
            array[i] = sc.nextInt();
        }

        int num1 = sc.nextInt();

        boolean found = false;

        int index = -1;
        for (int i = 0; i < length; i++) {
            if (array[i] == num1) {
                index = i;
                found = true;
                break;
            }
        }

        if (found) {
            System.out.println(num1 + " is index " + index);
        } else {
            System.out.println("Element not found.");
        }
    }
}
Leave a Comment