saif Active member
| Subject: JAVA Program to generate truth Tables Wed Feb 24, 2010 3:04 am | |
| I just made a prog. to generate truth table for three variable expression of type a.b+b.c+c.a+a.b.c+ ..... (single variable not allowed in expression)(input should be in ablove format only) Enter 3 Vriable expression with a,b,c a.b+b.c+c.a 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 1 1 1
Enter 3 Vriable expression with a,b,c a.b.c+a.b 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 1 1 1 1 1
import java.io.*; import java.util.*; class TruthTableMaker { public static void main(String args[])throws IOException { System.out.println("Enter 3 Vriable expression with a,b,c"); BufferedReader obj =new BufferedReader(new InputStreamReader(System.in)); String s=obj.readLine(); int a[][]=new int[8][3]; int x=0; for(int i=0;i<8;i++) { a[i][2]=i%2; x=i/2; a[i][1]=x%2; x=x/2; a[i][0]=x; } String t=""; int o[]=new int[8]; char ch;int y=1; for(int r=0;r<8;r++) { StringTokenizer st=new StringTokenizer(s,"+"); for(int k=0;k<=st.countTokens();k++) { t=st.nextToken(); int ab=t.length()/2; for(int q=0;q<=ab;q++) { ch=t.charAt(0); if(t.length()>1) {t=t.substring(2);} switch(ch) { case 'a': y=y*a[r][0];break; case 'b': y=y*a[r][1];break; case 'c': y=y*a[r][2];break; } } if(y==1) {o[r]=1;} y=1; } } for(int i=0;i<8;i++) { for(int j=0;j<3;j++) { System.out.print(a[i][j]+" "); } System.out.println(" "+o[i]); } } } |
|
sa12 Active member
| Subject: Re: JAVA Program to generate truth Tables Wed Feb 24, 2010 3:20 am | |
| Cool! Though I don't think its much probable. How do you post code without losing half of it? |
|
saif Active member
| Subject: Re: JAVA Program to generate truth Tables Wed Feb 24, 2010 8:12 am | |
| i did't wanted to make the code too long thats why it is not much portable |
|
Sponsored content
| Subject: Re: JAVA Program to generate truth Tables | |
| |
|