prog2.java


/*
	This Java example shows how to declare and use 
	Java primitive boolean variables.
	The output is a HTML document. 
*/

public class prog2 {

	public static void main( String[] args )
	{
		boolean[] a = {false, true, false, true, false, true, false, true};
		boolean[] b = {false,  false, true, true, false, false, true, true};
		boolean[] c = {false,  false, false, false, true, true, true, true};
		int s, d1, d0, f1, f2;
	
		System.out.println("<html>\n<head><title>Multiplexer</title></head>\n<body>");
		System.out.println("<p><table border>");
		System.out.println("<tr><th>S<th>D1<th>D0<th>F1<th>F2");

		for (int i=0; i<a.length; i++) {
			boolean f = (a[i] && !c[i]) || (b[i] && c[i]);
			s = c[i]? 1: 0;
			d1 = b[i]? 1: 0;
			d0 = a[i]? 1: 0;
			f1 = f? 1: 0;
			f2 = c[i]? d1: d0;
			System.out.printf("<tr align=center><td>%d<td>%d<td>%d<td>%d<td>%d\n",s,d1,d0,f1,f2);
		}
		System.out.println("</table>\n</body>\n</html>");
	}
}
	


Results

SD1D0F1F2
00000
00111
01000
01111
10000
10100
11011
11111


Maintained by John Loomis, updated Mon Sep 05 20:17:14 2011