Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author Jones
- */
- public class Soma {
- public static void encherVetor(int vet[], int max) {
- for (int i = 0; i < max; i++) {
- vet[i] = 1;
- if (i < max - 1) {
- System.out.print(vet[i] + " + ");
- } else {
- System.out.println(vet[i] + " = " + max);
- }
- }
- vet[0]++;
- }
- public static void main(String[] args) {
- int max = 10;
- int[] vet = new int[max];
- int i = 1, j, k, h = 1, soma = 0;
- encherVetor(vet, max);
- while (vet[0] < max) {
- i = 1;
- while (vet[i] <= vet[i - 1]) {
- soma = 0;
- for (j = 0; j < max; j++) {
- soma += vet[j];
- if (soma == max) {
- for (k = 0; k <= j; k++) {
- if (k < j) {
- System.out.print(vet[k] + " + ");
- } else {
- System.out.println(vet[k] + " = " + max);
- }
- }
- break;
- }
- }
- for (k = i + 1; k < max; k++) {
- vet[k] = 1;
- }
- vet[i]++;
- if (vet[i] > vet[i - 1]) {
- break;
- }
- if (i < j - 1) {
- i++;
- } else {
- i = h;
- if ((h < j - 1) && (h > 1)) {
- h++;
- } else {
- h = 1;
- }
- }
- }
- h = 1;
- vet[0]++;
- for (k = 1; k < max; k++) {
- vet[k] = 1;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment