How to solve Cannot invoke “String.compareTo(String)” because “[]” is null?

import java.util.Scanner; public class Search { static Scanner scanner = new Scanner(System.in); static Scanner kb = new Scanner(System.in); static Scanner kb2 = new Scanner(System.in); …

Swapping elements in an array Java

I am working on a classes challenge in school. We have to great a Boat class and Harbor class. I have gotten every test to work except the final test of where boats are parked in the Harbor. The …

traverse an array in GUI Java

I am doing a questionnaire with questions and written answers. I need that when adding the answer, press the main button, tell me if it is correct or not and show me the other question of the array, …

Printing results from an array seperately from user input in java

So I’m trying to create a program that takes in the student’s GPA and prints out if they are graduating at an honor’s level, graduating, or not graduating. I have most of the code figured out, but I …

Analysis of recursive approach for rotating an array of integers

While solving Array rotation on LeetCode, I wrote a recursive algorithm to solve the problem: Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: nums …

Game Of Life game: Check 2D array 8 closest surroundings; ArrayIndexOutOfBoundsException issue

I have encountered this problem and i couldn’t find the solution. There is a 2D array with only zeros and ones in it (the size of the array doesnt really matter, i worked with 10×10). Zero means dead …

Is there a way to copy int[] to another int[] without repeated ints?

We can’t use ArrayList or something like that, because the teacher told us to not use them, so I got stuck at this point. The signature of the function is: public static int[] deleteNth(int[] elements,…

How can i make my turn my text file to 40×40 matrix [closed]

In my code i need to read my text file and create a 40×40 matrix however my array only reads the first line Here is my code; String worldData = “world.txt”; File worldFile = new File(…

Sort List of Strings arrays in Java

I’m trying to make a program that consists of an array of Strings . now I need to sort them in order ‘PJ’, ‘GHS’, ‘FJ’, ‘PAS’ and date. input : listOfStringArrays.add(new String[] { “200608&…

How to calculate the time complexity of this program? (Checking subarray in greater array)

Java program to check if an array is subarray of another array class // Function to check if an array is // subarray of another array static boolean isSubArray(int A[], int B[], …