Click here to Skip to main content
15,559,732 members
Home / Discussions / Java
   

Java

 
GeneralRe: Which coding language is best for developing web apps? Pin
Richard Deeming14-Dec-22 3:48
mveRichard Deeming14-Dec-22 3:48 
GeneralRe: Which coding language is best for developing web apps? Pin
Richard MacCutchan14-Dec-22 3:58
mveRichard MacCutchan14-Dec-22 3:58 
AnswerRe: Which coding language is best for developing web apps? Pin
Gerry Schmitz14-Dec-22 10:10
mveGerry Schmitz14-Dec-22 10:10 
QuestionPor favor alguien q me ayude con estos ejercicios en netbenas en formulario jframe Pin
Joel Jordan3-Dec-22 14:00
Joel Jordan3-Dec-22 14:00 
AnswerRe: Por favor alguien q me ayude con estos ejercicios en netbenas en formulario jframe Pin
PIEBALDconsult3-Dec-22 14:16
professionalPIEBALDconsult3-Dec-22 14:16 
QuestionHow to put the condition if the array may be empty? Pin
Cris29M26-Nov-22 3:37
Cris29M26-Nov-22 3:37 
AnswerRe: How to put the condition if the array may be empty? Pin
Richard MacCutchan26-Nov-22 4:04
mveRichard MacCutchan26-Nov-22 4:04 
GeneralRe: How to put the condition if the array may be empty? Pin
Cris29M26-Nov-22 4:43
Cris29M26-Nov-22 4:43 
"
Why are you trying to access elements of an empty array? 
"

Because is in the statement description. I have some failed tests and I thought maybe because of that.


Note that input array may be empty.




I tried like this, but still it's not working.

Java
<pre>class CycleSwap {
     static void cycleSwap(int[] array) {
        int shift = 1;

        reverse(array, 0, array.length - 1);
        reverse(array, shift, array.length - 1);
    }

     static void cycleSwap(int[] array, int shift) {
         //shift = shift % array.length;
        reverse(array, 0, array.length - 1);
        reverse(array, 0, shift - 1);
        reverse(array, shift, array.length - 1);
    }

    private static void reverse(int[] nums, int i, int j) {
        while (i < j) {
            int temp = nums[i];
            nums[i] = nums[j];
            nums[j] = temp;
            i++;
            j--;
        }
    }

    public static void main(String[] args) {

        {
            int[] array = new int[]{};
            if (array.length == 0) {
                System.out.println(0);
            } else {
                CycleSwap.cycleSwap(array, 2);
                System.out.println(Arrays.toString(array));
            }
        }
     }
}



I get this result:
[ERROR]   CycleSwapTest.testCycleSwapEmptyCaseShift:44 � ArrayIndexOutOfBounds Index 0 o...


How can I fix that?
GeneralRe: How to put the condition if the array may be empty? Pin
Richard MacCutchan26-Nov-22 5:41
mveRichard MacCutchan26-Nov-22 5:41 
GeneralRe: How to put the condition if the array may be empty? Pin
Cris29M26-Nov-22 5:53
Cris29M26-Nov-22 5:53 
QuestionAddress Book System Help Pin
Ghost 717-Nov-22 20:19
Ghost 717-Nov-22 20:19 
SuggestionRe: Address Book System Help Pin
Richard MacCutchan17-Nov-22 21:38
mveRichard MacCutchan17-Nov-22 21:38 
AnswerRe: Address Book System Help Pin
CHill6018-Nov-22 1:02
mveCHill6018-Nov-22 1:02 
QuestionTravel Salesman Problem find itinerary with highest visited sites attractiveness score Pin
Faroug Tifratene16-Nov-22 1:36
Faroug Tifratene16-Nov-22 1:36 
QuestionJavaFX ScrollPane scroll child to bottom Pin
MVSoftVM14-Nov-22 7:30
MVSoftVM14-Nov-22 7:30 
AnswerRe: JavaFX ScrollPane scroll child to bottom Pin
englebart19-Nov-22 16:53
professionalenglebart19-Nov-22 16:53 
QuestionError while fetching Path locally during unit testing but not at runtime Pin
saurabh jasmeen mehta12-Nov-22 20:44
saurabh jasmeen mehta12-Nov-22 20:44 
AnswerRe: Error while fetching Path locally during unit testing but not at runtime Pin
Richard MacCutchan12-Nov-22 22:15
mveRichard MacCutchan12-Nov-22 22:15 
AnswerRe: Error while fetching Path locally during unit testing but not at runtime Pin
jschell14-Nov-22 7:36
jschell14-Nov-22 7:36 
Questionradiusofcircle Pin
Halima Kidiwala9-Nov-22 18:03
Halima Kidiwala9-Nov-22 18:03 
AnswerRe: radiusofcircle Pin
Richard MacCutchan9-Nov-22 23:00
mveRichard MacCutchan9-Nov-22 23:00 
Questioncheck and correct the following code Pin
EngySamy23-Oct-22 15:40
EngySamy23-Oct-22 15:40 
GeneralRe: check and correct the following code Pin
Richard MacCutchan23-Oct-22 22:50
mveRichard MacCutchan23-Oct-22 22:50 
GeneralRe: check and correct the following code Pin
EngySamy23-Oct-22 23:55
EngySamy23-Oct-22 23:55 
GeneralRe: check and correct the following code Pin
Richard MacCutchan24-Oct-22 0:24
mveRichard MacCutchan24-Oct-22 0:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.