MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / main

Method main

Programs/KnapSack.java:35–58  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

33 }
34
35 public static void main(String[] args)
36 {
37 int i, n, W;
38 Scanner sc = new Scanner(System.in);
39 System.out.println("Enter the number of items : ");
40 n = sc.nextInt();
41 System.out.println("Enter the maximum weight/capacity : ");
42 W = sc.nextInt();
43 int wt[] = new int[n];
44 int val[] = new int[n];
45 System.out.println("Enter the weights of the items : ");
46 for(i=0; i<n; i++)
47 {
48 wt[i] = sc.nextInt();
49 }
50 System.out.println("Enter their corresponding values : ");
51 for(i=0; i<n; i++)
52 {
53 val[i] = sc.nextInt();
54 }
55 KnapSack ob = new KnapSack();
56 int res = ob.knapSack(W, wt, val, n);
57 System.out.println("Total profit : "+res);
58 }
59}

Callers

nothing calls this directly

Calls 1

knapSackMethod · 0.95

Tested by

no test coverage detected