Created
September 12, 2014 14:14
-
-
Save Happsson/945bdc1352a1d5767c04 to your computer and use it in GitHub Desktop.
upg2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package math; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
public class Upg5 { | |
static int hits = 0; | |
static int all = 0; | |
static ArrayList<int[]> polynom; | |
public static void main (String[] args){ | |
polynom = new ArrayList<int[]>(); | |
for(int x1 = 0; x1 <= 50; x1++){ | |
for(int x2 = 0; x2 <= 50; x2++){ | |
for(int x3 = 0; x3<=50; x3++){ | |
for(int x4 = 0; x4 <= 50;x4++){ | |
if(x1+x2+x3+x4==50) all++; | |
if(x1>=0 && x2>=0 && x3>=0 && x4>x3 && (x1+x2+x3+x4==50)){ | |
int[] add = {x1,x2,x3,x4}; | |
polynom.add(add); | |
hits++; | |
} | |
} | |
} | |
} | |
} | |
int x3Max=0; | |
for(int[] test : polynom){ | |
if(test[2] > x3Max) x3Max = test[2]; | |
} | |
System.out.println("Antal lösningar: " + hits + ".\nx3 är max " + x3Max + ". \nAlla lösningar utan villkor är: " + all); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment