0
Help solve the task. Please, write the code
It is necessary to summarize any two numbers (double) that are entered by the user through a space
3 Réponses
+ 2
Have you tried to do it yet? don't forget to include the code so others can understand what your problem is. Anyways, what do you mean "through a space"?
+ 1
import java.util.Scanner;
class MyClass {
public static void main(String[] args)
{
// You didn't declare "array" variable
// declare "array" before you use it
// TIPS: To avoid confusion give your
// array a descriptive name rather than
// just "array". e.g. intArray
int[] array = {1,2,3,4,5,6,7,8,9,10};
// You didn't declare "variable"
// TIPS: To avoid confusion name the
// variables by their purpose
// e.g. here you can nsme it "summary"
int variable = 0;
for (int i = 0; i < array.length; i++)
{
variable += array[i];
}
System.out.println("Summary of array values: " + variable);
}
}
I see you created a Scanner in your code, but it wasn't being properly used, so I remove it in this.