Advertisement
MixDeath

Gdp A3

Nov 12th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. package de.uniwue.gdp.subsetsum;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5. import java.lang.Math;
  6.  
  7. public class SubsetSum {
  8.  
  9. public static void main(String[] args) {
  10.  
  11.  
  12. Scanner s = new Scanner(System.in);
  13. System.out.println("How many numbers should be read?");
  14.  
  15. int n = s.nextInt();
  16. Long M[] = new Long[n];
  17.  
  18. String place = "";
  19.  
  20.  
  21. for (int i = 1; i <= n; i++){
  22.  
  23. if ((i % 10) == 1 && i != 11) {
  24. place = "st";
  25. } else if ((i % 10) == 2 && i != 12) {
  26. place = "nd";
  27. } else if ((i % 10) == 3 && i != 13) {
  28. place = "rd";
  29. } else if ((i % 10) > 3 || i == 11 || i == 12 || i == 13) {
  30. place = "th";
  31. }
  32.  
  33.  
  34. System.out.println("Enter "+ i + place + " number:");
  35. M[i-1] = s.nextLong();
  36. }
  37.  
  38. System.out.println(Arrays.toString(M));
  39.  
  40. for(long x = 0; x < Math.pow(2,n); x++){
  41. for(int i = 0; i < n ; i++){
  42. if ( ((Long.parseLong(Long.toBinaryString(x)) >> i) == 1) )
  43. {
  44.  
  45. System.out.println(M[i]);
  46.  
  47. }
  48.  
  49. }
  50. System.out.println();
  51. }
  52.  
  53.  
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement