Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.uniwue.gdp.subsetsum;
- import java.util.Arrays;
- import java.util.Scanner;
- import java.lang.Math;
- public class SubsetSum {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- System.out.println("How many numbers should be read?");
- int n = s.nextInt();
- Long M[] = new Long[n];
- String place = "";
- for (int i = 1; i <= n; i++){
- if ((i % 10) == 1 && i != 11) {
- place = "st";
- } else if ((i % 10) == 2 && i != 12) {
- place = "nd";
- } else if ((i % 10) == 3 && i != 13) {
- place = "rd";
- } else if ((i % 10) > 3 || i == 11 || i == 12 || i == 13) {
- place = "th";
- }
- System.out.println("Enter "+ i + place + " number:");
- M[i-1] = s.nextLong();
- }
- System.out.println(Arrays.toString(M));
- for(long x = 0; x < Math.pow(2,n); x++){
- for(int i = 0; i < n ; i++){
- if ( ((Long.parseLong(Long.toBinaryString(x)) >> i) == 1) )
- {
- System.out.println(M[i]);
- }
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement