Printing the sums of numbers from with only 1 loop [on hold]











up vote
-2
down vote

favorite












   public class nawar {

public static void main(String args) {
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 1, 4, sumRange(1, 4));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 2, 5, sumRange(2, 5));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 47, 47, sumRange(47, 47));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", -12, 5, sumRange(-12, 5));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 7, 2, sumRange(7, 2));


}

public static int sumRange(int i1, int i2) {
int sum = 0;
for (int i = i1; i <= i2; i++)
sum += i;

return sum;
}

}


I want it to print these following numbers: 10 14 47 - 1 -1
But I get 10, 14, 47, -63 and 0.
How do i change and what should I do?










share|improve this question







New contributor




knashejhej is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Martin R, IEatBagels, Toby Speight, Mast, tinstaafl 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Martin R, IEatBagels, Toby Speight, Mast, tinstaafl

If this question can be reworded to fit the rules in the help center, please edit the question.













  • This question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Mast
    2 days ago















up vote
-2
down vote

favorite












   public class nawar {

public static void main(String args) {
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 1, 4, sumRange(1, 4));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 2, 5, sumRange(2, 5));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 47, 47, sumRange(47, 47));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", -12, 5, sumRange(-12, 5));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 7, 2, sumRange(7, 2));


}

public static int sumRange(int i1, int i2) {
int sum = 0;
for (int i = i1; i <= i2; i++)
sum += i;

return sum;
}

}


I want it to print these following numbers: 10 14 47 - 1 -1
But I get 10, 14, 47, -63 and 0.
How do i change and what should I do?










share|improve this question







New contributor




knashejhej is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Martin R, IEatBagels, Toby Speight, Mast, tinstaafl 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Martin R, IEatBagels, Toby Speight, Mast, tinstaafl

If this question can be reworded to fit the rules in the help center, please edit the question.













  • This question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Mast
    2 days ago













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











   public class nawar {

public static void main(String args) {
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 1, 4, sumRange(1, 4));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 2, 5, sumRange(2, 5));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 47, 47, sumRange(47, 47));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", -12, 5, sumRange(-12, 5));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 7, 2, sumRange(7, 2));


}

public static int sumRange(int i1, int i2) {
int sum = 0;
for (int i = i1; i <= i2; i++)
sum += i;

return sum;
}

}


I want it to print these following numbers: 10 14 47 - 1 -1
But I get 10, 14, 47, -63 and 0.
How do i change and what should I do?










share|improve this question







New contributor




knashejhej is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











   public class nawar {

public static void main(String args) {
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 1, 4, sumRange(1, 4));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 2, 5, sumRange(2, 5));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 47, 47, sumRange(47, 47));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", -12, 5, sumRange(-12, 5));
System.out.printf("Summan av talen i intervallet %d till %d är %d%n", 7, 2, sumRange(7, 2));


}

public static int sumRange(int i1, int i2) {
int sum = 0;
for (int i = i1; i <= i2; i++)
sum += i;

return sum;
}

}


I want it to print these following numbers: 10 14 47 - 1 -1
But I get 10, 14, 47, -63 and 0.
How do i change and what should I do?







java






share|improve this question







New contributor




knashejhej is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




knashejhej is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




knashejhej is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









knashejhej

1




1




New contributor




knashejhej is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





knashejhej is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






knashejhej is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by Martin R, IEatBagels, Toby Speight, Mast, tinstaafl 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Martin R, IEatBagels, Toby Speight, Mast, tinstaafl

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by Martin R, IEatBagels, Toby Speight, Mast, tinstaafl 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Martin R, IEatBagels, Toby Speight, Mast, tinstaafl

If this question can be reworded to fit the rules in the help center, please edit the question.












  • This question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Mast
    2 days ago


















  • This question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Mast
    2 days ago
















This question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
– Mast
2 days ago




This question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
– Mast
2 days ago















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Quarter-circle Tiles

build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

Mont Emei