Skip to content

Instantly share code, notes, and snippets.

@ahlens
Created July 20, 2017 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahlens/4ce149fc5328d2b058ab1e1b8ba15888 to your computer and use it in GitHub Desktop.
Save ahlens/4ce149fc5328d2b058ab1e1b8ba15888 to your computer and use it in GitHub Desktop.
SamouczekProgramisty
// 1. Napisz metodę pobierającą dwuelementową tablicę liczb i zwracający ich sumę.
Scanner scanner = new Scanner(System.in);
double[] exerciseArray1 = new double[3];
double sum = 0;
System.out.println("Enter values for your array:");
// Entered values are stored in array
for (int i = 0; i < exerciseArray1.length; i++) {
exerciseArray1[i] = scanner.nextDouble();
}
for (int element = 0; element < exerciseArray1.length; element++) {
sum += exerciseArray1[element]; // W jaki sposób zsumować elementy, żeby wyświetliły się w jednym wyniku?
System.out.println(sum);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment