Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. public static void main(String[] args) {
  2. // TODO Auto-generated method stub
  3. int data = 1256;
  4. double di[] = new double[4];
  5. char op[] = new char[3];
  6. double result;
  7. di[0] = data / 1000;
  8. di[1] = data/100%10;
  9. di[2] = data/10%10;
  10. di[3] = data%10;
  11.  
  12. for(int a=0;a<4;a++){
  13. for(int b=0;b<4;b++){
  14. for(int c=0;c<4;c++){
  15. for(int d=0;d<4;d++){
  16. if(!(a==b||a==c||a==d||b==c||b==d||c==d)){
  17. for (int i = 0; i < 4; i++) {
  18. for (int j = 0; j < 4; j++) {
  19. for (int k = 0; k < 4; k++) {
  20. for (int l = 0; l < 4; l++) {
  21. result = di[a];
  22. switch(i){
  23. case 0: result+=di[b];op[0]='+';
  24. break;
  25. case 1: result-=di[b];op[0]='-';
  26. break;
  27. case 2: result*=di[b];op[0]='*';
  28. break;
  29. case 3: result/=di[b];op[0]='/';
  30. break;
  31. }/////////////////////////////////////1
  32. switch(j){
  33. case 0: result+=di[c];op[1]='+';
  34. break;
  35. case 1: result-=di[c];op[1]='-';
  36. break;
  37. case 2: result*=di[c];op[1]='*';
  38. break;
  39. case 3: result/=di[c];op[1]='/';
  40. break;
  41. }////////////////////////////////////2
  42. switch(k){
  43. case 0: result+=di[d];op[2]='+';
  44. break;
  45. case 1: result-=di[d];op[2]='-';
  46. break;
  47. case 2: result*=di[d];op[2]='*';
  48. break;
  49. case 3: result/=di[d];op[2]='/';
  50. break;
  51. }////////////////////////////////////3
  52. if(result==24)System.out.println((int)di[0]+""+op[0]+""+(int)di[1]+""+op[1]+""+(int)di[2]+""+op[2]+""+(int)di[3]+"="+(int)result);
  53. }
  54. }
  55. }
  56. }
  57.  
  58. }
  59. }
  60. }
  61. }
  62.  
  63.  
  64. }
  65. ////////end method//////////////////////////////////////
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement