Guest User

Untitled

a guest
Jul 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. /**
  7.  *
  8.  * @author Jones
  9.  */
  10. public class Soma {
  11.  
  12.     public static void encherVetor(int vet[], int max) {
  13.         for (int i = 0; i < max; i++) {
  14.             vet[i] = 1;
  15.             if (i < max - 1) {
  16.                 System.out.print(vet[i] + " + ");
  17.             } else {
  18.                 System.out.println(vet[i] + " = " + max);
  19.             }
  20.         }
  21.         vet[0]++;
  22.     }
  23.  
  24.     public static void main(String[] args) {
  25.         int max = 10;
  26.         int[] vet = new int[max];
  27.         int i = 1, j, k, h = 1, soma = 0;
  28.  
  29.         encherVetor(vet, max);
  30.  
  31.         while (vet[0] < max) {
  32.             i = 1;
  33.             while (vet[i] <= vet[i - 1]) {
  34.                 soma = 0;
  35.                 for (j = 0; j < max; j++) {
  36.                     soma += vet[j];
  37.                     if (soma == max) {
  38.  
  39.                         for (k = 0; k <= j; k++) {
  40.                             if (k < j) {
  41.                                 System.out.print(vet[k] + " + ");
  42.                             } else {
  43.                                 System.out.println(vet[k] + " = " + max);
  44.                             }
  45.                         }
  46.                         break;
  47.                     }
  48.                 }
  49.                 for (k = i + 1; k < max; k++) {
  50.                     vet[k] = 1;
  51.  
  52.                 }
  53.                 vet[i]++;
  54.                 if (vet[i] > vet[i - 1]) {
  55.                     break;
  56.                 }
  57.                 if (i < j - 1) {
  58.                     i++;
  59.                 } else {
  60.                     i = h;
  61.                     if ((h < j - 1) && (h > 1)) {
  62.                         h++;
  63.                     } else {
  64.                         h = 1;
  65.                     }
  66.  
  67.                 }
  68.             }
  69.             h = 1;
  70.             vet[0]++;
  71.             for (k = 1; k < max; k++) {
  72.                 vet[k] = 1;
  73.             }
  74.         }
  75.     }
  76. }
Add Comment
Please, Sign In to add comment