Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class arrex1 {
- public static void main(String[] args) {
- int[] arr = new int[10];
- Scanner s = new Scanner(System.in);
- System.out.println("Please enter 10 numbers:");
- for (int i = 0; i < arr.length; i += 1) {// loop for input from user to the array
- arr[i] = s.nextInt();
- }
- for (int i = 0; i < arr.length; i += 1) {// loop for output from the array
- if (arr[i] % 2 == 0) {// checking if the number in the current index is even
- System.out.print(arr[i] + " ");// prints even numbers
- }
- }
- }
- }
- ------------------------------------------------------------------------------------------------------
- import java.util.Scanner;
- public class arrex2 {
- public static void main(String[] args) {
- char[] arr = new char[10];
- Scanner s = new Scanner(System.in);
- System.out.println("Please enter 10 characters:");
- for (int i = 0; i < arr.length; i += 1) {// loop for input from user to the array
- arr[i] = s.next().charAt(0);
- }
- for (int i = 0; i < arr.length; i += 1) {// loop for output from the array
- if (arr[i] <= 'Z' && arr[i] >= 'A') {// checking if the chars in the current index is capital letter
- System.out.print(i + " ");// prints the index
- }
- }
- }
- }
- ----------------------------------------------------------------------------------------------
- import java.util.Scanner;
- public class arrex3 {
- public static void main(String[] args) {
- int[] arr = new int[10];
- for (int i = 0, count = 0; i < arr.length; count += 1) {
- if (count % 3 == 0) {// checking if count is divided in 3
- arr[i] = count;// adding the number to the array
- i += 1;// inc the index
- }
- }
- for (int i = 0; i < arr.length; i += 1) {// loop for output from the array
- System.out.print(arr[i] + " ");// prints the numbers that divided in 3
- }
- }
- }
- ----------------------------------------------------------------------------------------------
- import java.util.Scanner;
- public class arrex4 {
- public static void main(String[] args) {
- int[] arr = new int[10];
- Scanner s = new Scanner(System.in);
- System.out.println("Please enter 10 numbers:");
- for (int i = 0; i < arr.length; i += 1) {// loop for input from user to the array
- arr[i] = s.nextInt();
- }
- for (int i = 0; i < arr.length; i += 1) {// loop for output from the array
- if (i % 2 == 0) {// checking if the current index is even
- arr[i] += 1;
- }
- }
- for (int i = 0; i < arr.length; i += 1) {// loop for output from the array
- System.out.print(arr[i] + " ");// prints the numbers
- }
- }
- }
- --------------------------------------------------------------------------------------
- import java.util.Scanner;
- public class arrex5 {
- public static void main(String[] args) {
- int[] arr = new int[10];
- Scanner s = new Scanner(System.in);
- System.out.println("Please enter 10 numbers:");
- for (int i = 0; i < arr.length; i += 1) {// loop for input from user to the array
- arr[i] = s.nextInt();
- }
- for (int i = 0; i < arr.length; i += 1) {// loop for output from the array
- if (i % 2 == 0) {// checking if the current index is even
- arr[i] += 1;
- }
- }
- for (int i = 0; i < arr.length; i += 1) {
- if (i % 3 == 0) {// checking if count is divided in 3
- arr[i] -= 1;// adding the number to the array
- }
- }
- for (int i = 0; i < arr.length; i += 1) {// loop for output from the array
- System.out.print(arr[i] + " ");// prints the numbers
- }
- }
- }
- -------------------------------------------------------------------------------------------
- import java.util.Scanner;
- public class arrex6 {
- public static void main(String[] args) {
- char[] arr = new char[10];
- int count = 0;
- Scanner s = new Scanner(System.in);
- System.out.println("Please enter 10 characters:");
- for (int i = 0; i < arr.length; i += 1) {// loop for input from user to the array
- arr[i] = s.next().charAt(0);
- }
- System.out.println("Please enter anther character:");
- char ch = s.next().charAt(0);// getting anther char from user
- for (int i = 0; i < arr.length; i += 1) {
- if (ch == arr[i]) {// checking if the char is found in the array
- count += 1;// count the time we found the char in the array
- }
- }
- System.out.println("The ch '" + ch + "' was found in the array " + count + " times");// result
- }
- }
- --------------------------------------------------------------------------------------------------------
- import java.util.Scanner;
- public class arrex7 {
- public static void main(String[] args) {
- int[] arr1 = new int[5];
- int[] arr2 = new int[5];
- Scanner s = new Scanner(System.in);
- System.out.println("Please enter 10 numbers:");
- for (int i = 0; i < arr1.length; i += 1) {// loop for input from user to the array1
- arr1[i] = s.nextInt();
- }
- System.out.println("Please enter 10 numbers:");
- for (int i = 0; i < arr2.length; i += 1) {// loop for input from user to the array2
- arr2[i] = s.nextInt();
- }
- for (int i = 0; i < arr1.length; i += 1) {
- for (int j = 0; j < arr2.length; j += 1) {
- if (arr1[i] == arr2[j]) {// checking if the numbers in the array are matched
- System.out.println("The index from arr1 is " + i);// result for the first array
- System.out.println("The index from arr2 is " + j);// result for the second array
- }
- }
- }
- }
- }
- -----------------------------------------------------------------------------------------------------------
- import java.util.Scanner;
- public class arrex8 {
- public static void main(String[] args) {
- int[] arr1 = new int[5];
- int[] arr2 = new int[5];
- int[] arr3 = new int[5];
- Scanner s = new Scanner(System.in);
- System.out.println("Please enter 5 numbers:");
- for (int i = 0; i < arr1.length; i += 1) {// loop for input from user to the array1
- arr1[i] = s.nextInt();
- }
- System.out.println("Please enter 5 numbers:");
- for (int i = 0; i < arr2.length; i += 1) {// loop for input from user to the array2
- arr2[i] = s.nextInt();
- }
- for (int i = 0; i < arr3.length; i += 1) {
- arr3[i] = arr1[i] + arr2[i];// summing the numbers from the first and second array
- }
- System.out.println();
- for (int i = 0; i < arr3.length; i += 1) {// loop for output from the array
- System.out.print(arr3[i] + " ");// prints the numbers
- }
- }
- }
- ------------------------------------------------------------------------------------------
- import java.util.Scanner;
- public class arrex9 {
- public static void main(String[] args) {
- char[] arr = new char[5];
- boolean b = false;
- Scanner s = new Scanner(System.in);
- System.out.println("Please enter 5 characters:");
- for (int i = 0; i < arr.length; i += 1) {// loop for input from user to the array
- arr[i] = s.next().charAt(0);
- }
- for (int i = 0; i < arr.length; i += 1) {
- for (int j = 1; j < arr.length; j += 1) {
- if (arr[i] == arr[j]) {// checking if the character is the same in all the array
- b = true;
- } else {
- b = false;
- j = i = arr.length;
- }
- }
- }
- if (b == true) {
- System.out.println("All the character in the array are the same");// result if all the characters are the
- // same
- } else {
- System.out.println("All the character in the array are not the same");// result if all the characters are
- // not the same
- }
- }
- }
- -------------------------------------------------------------------------------------------------------
- import java.util.Scanner;
- public class arrex10 {
- public static void main(String[] args) {
- int[] arr1 = new int[5];
- boolean b = false;
- Scanner s = new Scanner(System.in);
- System.out.println("Please enter 5 numbers:");
- for (int i = 0; i < arr1.length; i += 1) {// loop for input from user to the array1
- arr1[i] = s.nextInt();
- }
- for (int i = 1; i < arr1.length; i += 1) {
- if (arr1[i] > arr1[i - 1]) {// checking if all the number is bigger then his previous in the array
- b = true;
- } else {
- b = false;
- i = arr1.length;
- }
- }
- if (b == true) {
- System.out.println("All the numbers are bigger then their previous");// result if all the numbers are bigger
- // then their previous
- } else {
- System.out.println("All the numbers are not bigger then their previos");// result if all the numbers are not
- // bigger then their previous
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment