Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- interface IterateOver
- {
- public void iterate(int i);
- }
- class ModuloEmatrizes
- {
- int[] anyArray = new int[5];
- int sum = 0;
- int productory = 1;
- public ModuloEmatrizes()
- {
- this.readValues();
- }
- public static void main(String[] args)
- {
- ModuloEmatrizes obj = new ModuloEmatrizes();
- obj.calcSum();
- obj.calcProd();
- obj.showUserResult();
- System.exit(1);
- }
- public void readValues()
- {
- this.loooop(
- (i) -> {
- this.anyArray[i] = Integer.parseInt(
- JOptionPane.showInputDialog("Input a number " + i)
- );
- }
- );
- }
- public void calcSum()
- {
- this.loooop(
- (i) -> {
- this.sum += this.anyArray[i];
- }
- );
- }
- public void calcProd()
- {
- this.loooop(
- (i) -> {
- this.productory *= this.anyArray[i];
- }
- );
- }
- public void loooop(IterateOver obj)
- {
- for (int i = 0; i <= this.anyArray.length - 1; i++)
- {
- obj.iterate(i);
- }
- }
- public void showUserResult()
- {
- JOptionPane.showMessageDialog(
- null,
- "Result:\n\nSum: " + this.sum +
- "\nProductory: " + this.productory
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement