java.lang.ArrayIndexOutOfBoundsException 2 out of 2 [duplicate]
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);
java new-operator
marked as duplicate by GBlodgett, Alessandro Da Rugna, Mark Rotteveel
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.
add a comment |
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);
java new-operator
marked as duplicate by GBlodgett, Alessandro Da Rugna, Mark Rotteveel
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 isSystem.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
add a comment |
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);
java new-operator
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
java new-operator
asked Nov 23 '18 at 22:10
Simon CankovSimon Cankov
1
1
marked as duplicate by GBlodgett, Alessandro Da Rugna, Mark Rotteveel
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
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 isSystem.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
add a comment |
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 isSystem.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
add a comment |
1 Answer
1
active
oldest
votes
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 <
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 <
add a comment |
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 <
add a comment |
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 <
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 <
answered Nov 23 '18 at 22:13
KreaseKrease
11.3k74159
11.3k74159
add a comment |
add a comment |
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