Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Arrays {
- public static void main(String[] args) {
- //----------WARM UP-----------------
- //---------------Ex1----------------
- /*
- int arr[] = new int[10];
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter 10 integers: ");
- for(int i = 0; i < arr.length; i+=1) {
- arr[i] = sc.nextInt();
- }
- for (int j = 0; j < arr.length; j+=1) {
- if(arr[j] % 2 == 0) {
- System.out.print(arr[j] + " ");
- }
- }
- */
- //---------------Ex2----------------
- /*
- char arr[] = new char[10];
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter 10 characters: ");
- for(int i = 0; i < arr.length; i+=1) {
- arr[i] = sc.next().charAt(0);
- }
- for (int j = 0; j < arr.length; j+=1) {
- if(arr[j] >= 'A' && arr[j] <= 'Z') {
- System.out.print(j + " ");
- }
- }
- */
- //---------------Ex3----------------
- /*
- int arr[] = new int[10];
- System.out.println("Please enter 10 integers: ");
- for(int i = 0; i < arr.length; i+=1) {
- arr[i] = i * 3;
- }
- for(int n : arr) {
- System.out.printf("%d ", n);
- }
- */
- //---------------Ex4----------------
- /*
- int arr[] = new int[11];
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter 10 integers: ");
- for(int i = 0; i < arr.length; i+=1) {
- arr[i] = sc.nextInt();
- }
- for (int j = 0; j < arr.length; j+=2) {
- arr[j] += 1;
- }
- for(int n : arr) {
- System.out.printf("%d ", n);
- }
- */
- //---------------Ex5----------------
- /*
- int arr[] = new int[10];
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter 10 integers: ");
- for(int i = 0; i < arr.length; i+=1) {
- arr[i] = sc.nextInt();
- }
- for (int j = 0; j < arr.length; j+=2) {
- arr[j] += 1;
- }
- for (int j = 0; j < arr.length; j+=3) {
- arr[j] -= 1;
- }
- for(int n : arr) {
- System.out.printf("%d ", n);
- }
- */
- //------------ Homework Assignments ----------
- //---------------Ex6----------------
- /*
- char arr[] = new char[10];
- char c;
- int acc = 0;
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter 10 characters: ");
- for(int i = 0; i < arr.length; i+=1) {
- arr[i] = sc.next().charAt(0);
- }
- System.out.println("Please enter a character: ");
- c = sc.next().charAt(0);
- for (char ch : arr) {
- if(ch == c) {
- acc += 1;
- }
- }
- System.out.printf("Number of appearances is: %d", acc);
- */
- //---------------Ex7----------------
- /*
- int[] arr1 = new int[5], arr2 = new int[5];
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter 5 integers: ");
- for(int i = 0; i < arr1.length; i+=1) {
- arr1[i] = sc.next().charAt(0);
- }
- System.out.println("Please enter another 5 integers: ");
- for(int i = 0; i < arr2.length; i+=1) {
- arr2[i] = sc.next().charAt(0);
- }
- for(int i = 0; i < arr1.length; i += 1) {
- for(int j = 0; j < arr2.length; j += 1) {
- if(arr1[i] == arr2[j]) {
- System.out.printf("Number are identical in indexes of arr1[%d] and arr2[%d].\n", i, j);
- }
- }
- }
- */
- //---------------Ex8----------------
- /*
- int[][] arr = new int[3][5];
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter 10 integers (5 for each array): ");
- for(int i = 0; i < arr.length - 1; i+=1) {
- for(int j = 0; j < arr[i].length; j += 1) {
- arr[i][j] = sc.nextInt();
- }
- }
- for(int i = 0; i < arr[2].length; i += 1) {
- arr[2][i] = arr[1][i] + arr[0][i];
- }
- System.out.println("The sum of the values in the arrays are:");
- for(int n : arr[2]) {
- System.out.printf("%d ", n);
- }
- */
- //---------------Ex9----------------
- /*
- char[] arr = new char[5];
- char c;
- boolean b = true;
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter 5 integers: ");
- for(int i = 0; i < arr.length; i+=1) {
- arr[i] = sc.next().charAt(0);
- }
- c = arr[0];
- for(int i = 1; i < arr.length; i += 1) {
- if(arr[i] != c) {
- b = false;
- break;
- }
- }
- if(b) {
- System.out.println("All values are the same");
- } else {
- System.out.println("Not all values are the same");
- }
- */
- //---------------Ex10----------------
- //
- int[] arr = new int[5];
- int n;
- boolean b = true;
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter 5 integers: ");
- for(int i = 0; i < arr.length; i+=1) {
- arr[i] = sc.next().charAt(0);
- }
- for(int i = 0; i < arr.length - 1; i += 1) {
- if(arr[i] >= arr[i + 1]) {
- b = false;
- break;
- }
- }
- if(b) {
- System.out.println("Values in the array are in ascending order");
- } else {
- System.out.println("Values in the array are not in order");
- }
- //
- }
- }
Add Comment
Please, Sign In to add comment