java.lang.ArrayIndexOutOfBoundsException 2 out of 2 [duplicate]












-2
















This question already has an answer here:




  • How to prevent ArrayIndexOutOfBoundsException in Java?

    23 answers




Can you please help I am new to proggraming and I don not even no what this error is caused from here is my code. I am trying to make a working Resistence formula but its not working.



 int n=kb.nextInt();
double massiv=new double[n];
for(int i=0;i<=massiv.length;i++){
massiv[i]=kb.nextDouble();
}
for(int i=0;i<=massiv.length;i++){
gr=massiv[i]*gr;
dr=massiv[i]+dr;
}
Re=gr/dr;
System.out.println(+Re);









share|improve this question













marked as duplicate by GBlodgett, Alessandro Da Rugna, Mark Rotteveel java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 8:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 3





    Change <= to <. Array's are zero indexed based, so the last index will be size -1, so you need to loop while less than the length

    – GBlodgett
    Nov 23 '18 at 22:10













  • What is System.out.println(+Re); supposed to do?

    – GBlodgett
    Nov 23 '18 at 22:11











  • Indexes in an array go from 0 to n-1 where n is the length of the array ... you are also accessing the nth index by using <= in your for loops ... so if you change it to <, you won't get the exception

    – mettleap
    Nov 23 '18 at 22:12
















-2
















This question already has an answer here:




  • How to prevent ArrayIndexOutOfBoundsException in Java?

    23 answers




Can you please help I am new to proggraming and I don not even no what this error is caused from here is my code. I am trying to make a working Resistence formula but its not working.



 int n=kb.nextInt();
double massiv=new double[n];
for(int i=0;i<=massiv.length;i++){
massiv[i]=kb.nextDouble();
}
for(int i=0;i<=massiv.length;i++){
gr=massiv[i]*gr;
dr=massiv[i]+dr;
}
Re=gr/dr;
System.out.println(+Re);









share|improve this question













marked as duplicate by GBlodgett, Alessandro Da Rugna, Mark Rotteveel java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 8:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 3





    Change <= to <. Array's are zero indexed based, so the last index will be size -1, so you need to loop while less than the length

    – GBlodgett
    Nov 23 '18 at 22:10













  • What is System.out.println(+Re); supposed to do?

    – GBlodgett
    Nov 23 '18 at 22:11











  • Indexes in an array go from 0 to n-1 where n is the length of the array ... you are also accessing the nth index by using <= in your for loops ... so if you change it to <, you won't get the exception

    – mettleap
    Nov 23 '18 at 22:12














-2












-2








-2









This question already has an answer here:




  • How to prevent ArrayIndexOutOfBoundsException in Java?

    23 answers




Can you please help I am new to proggraming and I don not even no what this error is caused from here is my code. I am trying to make a working Resistence formula but its not working.



 int n=kb.nextInt();
double massiv=new double[n];
for(int i=0;i<=massiv.length;i++){
massiv[i]=kb.nextDouble();
}
for(int i=0;i<=massiv.length;i++){
gr=massiv[i]*gr;
dr=massiv[i]+dr;
}
Re=gr/dr;
System.out.println(+Re);









share|improve this question















This question already has an answer here:




  • How to prevent ArrayIndexOutOfBoundsException in Java?

    23 answers




Can you please help I am new to proggraming and I don not even no what this error is caused from here is my code. I am trying to make a working Resistence formula but its not working.



 int n=kb.nextInt();
double massiv=new double[n];
for(int i=0;i<=massiv.length;i++){
massiv[i]=kb.nextDouble();
}
for(int i=0;i<=massiv.length;i++){
gr=massiv[i]*gr;
dr=massiv[i]+dr;
}
Re=gr/dr;
System.out.println(+Re);




This question already has an answer here:




  • How to prevent ArrayIndexOutOfBoundsException in Java?

    23 answers








java new-operator






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 22:10









Simon CankovSimon Cankov

1




1




marked as duplicate by GBlodgett, Alessandro Da Rugna, Mark Rotteveel java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 8:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by GBlodgett, Alessandro Da Rugna, Mark Rotteveel java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 8:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 3





    Change <= to <. Array's are zero indexed based, so the last index will be size -1, so you need to loop while less than the length

    – GBlodgett
    Nov 23 '18 at 22:10













  • What is System.out.println(+Re); supposed to do?

    – GBlodgett
    Nov 23 '18 at 22:11











  • Indexes in an array go from 0 to n-1 where n is the length of the array ... you are also accessing the nth index by using <= in your for loops ... so if you change it to <, you won't get the exception

    – mettleap
    Nov 23 '18 at 22:12














  • 3





    Change <= to <. Array's are zero indexed based, so the last index will be size -1, so you need to loop while less than the length

    – GBlodgett
    Nov 23 '18 at 22:10













  • What is System.out.println(+Re); supposed to do?

    – GBlodgett
    Nov 23 '18 at 22:11











  • Indexes in an array go from 0 to n-1 where n is the length of the array ... you are also accessing the nth index by using <= in your for loops ... so if you change it to <, you won't get the exception

    – mettleap
    Nov 23 '18 at 22:12








3




3





Change <= to <. Array's are zero indexed based, so the last index will be size -1, so you need to loop while less than the length

– GBlodgett
Nov 23 '18 at 22:10







Change <= to <. Array's are zero indexed based, so the last index will be size -1, so you need to loop while less than the length

– GBlodgett
Nov 23 '18 at 22:10















What is System.out.println(+Re); supposed to do?

– GBlodgett
Nov 23 '18 at 22:11





What is System.out.println(+Re); supposed to do?

– GBlodgett
Nov 23 '18 at 22:11













Indexes in an array go from 0 to n-1 where n is the length of the array ... you are also accessing the nth index by using <= in your for loops ... so if you change it to <, you won't get the exception

– mettleap
Nov 23 '18 at 22:12





Indexes in an array go from 0 to n-1 where n is the length of the array ... you are also accessing the nth index by using <= in your for loops ... so if you change it to <, you won't get the exception

– mettleap
Nov 23 '18 at 22:12












1 Answer
1






active

oldest

votes


















2














Arrays are 0-indexed. An array of size 2 has 2 indexes: 0 and 1. Your loops are trying to access index 2 (since they're using <=), which doesn't exist.



Replace <= in your for-loops with <






share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Arrays are 0-indexed. An array of size 2 has 2 indexes: 0 and 1. Your loops are trying to access index 2 (since they're using <=), which doesn't exist.



    Replace <= in your for-loops with <






    share|improve this answer




























      2














      Arrays are 0-indexed. An array of size 2 has 2 indexes: 0 and 1. Your loops are trying to access index 2 (since they're using <=), which doesn't exist.



      Replace <= in your for-loops with <






      share|improve this answer


























        2












        2








        2







        Arrays are 0-indexed. An array of size 2 has 2 indexes: 0 and 1. Your loops are trying to access index 2 (since they're using <=), which doesn't exist.



        Replace <= in your for-loops with <






        share|improve this answer













        Arrays are 0-indexed. An array of size 2 has 2 indexes: 0 and 1. Your loops are trying to access index 2 (since they're using <=), which doesn't exist.



        Replace <= in your for-loops with <







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 22:13









        KreaseKrease

        11.3k74159




        11.3k74159















            Popular posts from this blog

            Berounka

            Sphinx de Gizeh

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...