Note that there are some explanatory texts on larger screens.

plurals
  1. PONo output for Subset program using string array
    primarykey
    data
    text
    <p>The below program should display subsets where elements are separated by '|'. Here i am using static String array allocation. But it doesn't show output for array size >19. It did not throw exception. How to resolve this?</p> <pre><code>class kkk { static int set[]={3,4,9,14,15,19,28,37,47,50,54,56,59,61,70,73,78,81,92,95,97,99}; static int arr_size=(int)Math.pow((double)2,(double)set.length); static String []abc=new String[arr_size+10]; static String wwf=""; static void subset(int x) { if(abc[0].equals("END")) { abc[0]=""+x; } else { int i,len=0,count=0; for(i=0;i&lt;abc.length;i++) { if(!abc[i].equals("END")){len=len+1;} } count=len; wwf=""; for(i=0;i&lt;len;i++) { wwf=abc[i]; wwf=wwf+"|"+x; abc[count]=wwf; count++; } abc[count]=""+x; } } static void sub() { int len=set.length,i; for(i=0;i&lt;len;i++) { subset(set[i]); } int count=0; for(i=0;i&lt;abc.length;i++) { System.out.println("count:"+count+++"-----"+abc[i]); } } public static void main(String args[]) { for(int i=0;i&lt;abc.length;i++) { abc[i]="END"; } sub(); } } </code></pre> <p>For ivanovic: Whats the output of the following program?</p> <pre><code>class kkk { static int valid_subset() { int count=0,len=abc.length,subset_count=0; for(int i=0;i&lt;len;i++) { if(!abc[i].equals("END")) { count=count+1; } } String www=""; for(int i=0;i&lt;count;i++) { int temp_large=0,sum=0,x=0; www=abc[i]; String fgr=""; for(int j=0;j&lt;www.length();j++) { if(!(""+www.charAt(j)).equals("|")) { fgr=fgr+www.charAt(j); x=Integer.parseInt(fgr); } else { if(x&gt;temp_large) { temp_large=x; } fgr=""; } } if(x&gt;temp_large) { temp_large=x; } fgr=""; for(int j=0;j&lt;www.length();j++) { if(!(""+www.charAt(j)).equals("|")) { fgr=fgr+www.charAt(j); x=Integer.parseInt(fgr); } else { if(x!=temp_large) { sum=sum+x; } fgr=""; } } if(x!=temp_large) { sum=sum+x; } if(temp_large==sum) { subset_count=subset_count+1; } } return subset_count; } static int set[]={3,4,9,14,15,19,28,37,47,50,54,56,59,61,70,73,78,81,92,95,97,99}; static int arr_size=(int)Math.pow((double)2,(double)set.length); static String []abc=new String[arr_size+10]; static String wwf=""; static void subset(int x) { if(abc[0].equals("END")) { abc[0]=""+x; } else { int i,len=0,count=0; for(i=0;i&lt;abc.length;i++) { if(!abc[i].equals("END")){len=len+1;} } count=len; wwf=""; for(i=0;i&lt;len;i++) { wwf=abc[i]; wwf=wwf+"|"+x; abc[count]=wwf; count++; } abc[count]=""+x; } } static void sub() { int len=set.length,i; for(i=0;i&lt;len;i++) { subset(set[i]); } /*int count=0; for(i=0;i&lt;abc.length;i++) { System.out.println("count:"+count+++"-----"+abc[i]); }*/ } public static void main(String args[]) { for(int i=0;i&lt;abc.length;i++) { abc[i]="END"; } sub(); System.out.println(valid_subset()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload