Don't like ads? PRO users don't see any ads ;-)
Guest

Display BCD con funzioni

By: a guest on May 1st, 2012  |  syntax: Java  |  size: 1.44 KB  |  hits: 56  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class bcd {
  2.         public static void main(String[] args) {
  3.            
  4.                 boolean a = false; // Queste sono le quttro entrate nel bcd
  5.                 boolean b = true;
  6.                 boolean c = false;
  7.                 boolean d = true;
  8.                
  9.                 boolean fa = !a&&!c||a&&c ||b||d; // uso le formule per calcolare se i segmenti sono accesi.   
  10.                 boolean fb = !c||a&&b||!a&&!b;
  11.                 boolean fc = a||!b||c;
  12.                 boolean fd = !a&&!c||b&&!c||d||!a&&b||a&&!b&&c;
  13.                 boolean fe = !a&&!c||!a&&b;
  14.                 boolean ff = d||!a&&c||!a&&!b||!b&&c;
  15.                 boolean fg = !a&&c||!b&&c||d||b&&!c;
  16.                 boolean ffb = ff&&fb;
  17.                 boolean fce = fc&&fe;
  18.                 //if per la stampa come se fosse un display 7 segmenti         
  19.                 if(fa == true){
  20.                         System.out.println(" ****");
  21.                 }
  22.                 else{
  23.                         System.out.println("    ");
  24.                 }
  25.                 if(ffb == true){
  26.                         System.out.println("*    *"+"\n"+"*    *"+"\n"+"*    *");
  27.                 }else if (fb == true){
  28.                         System.out.println("     *"+"\n"+"     *"+"\n"+"     *");
  29.                 }else{
  30.                         System.out.println("*     "+"\n"+"*     "+"\n"+"*     ");
  31.                 }
  32.                 if(fg == true){
  33.                         System.out.println(" ****");
  34.                 }else{
  35.                         System.out.println("    ");
  36.                 }
  37.                 if(fce == true){
  38.                         System.out.println("*    *"+"\n"+"*    *"+"\n"+"*    *");
  39.                 }else if (fc == true){
  40.                         System.out.println("     *"+"\n"+"     *"+"\n"+"     *");// stessa cosa che per i segmenti ff e fb!
  41.                 }else{
  42.                         System.out.println("*     "+"\n"+"*     "+"\n"+"*     ");
  43.                 }
  44.                 if(fd == true){
  45.                         System.out.println(" ****");
  46.                 }else{
  47.                         System.out.println("    ");
  48.                 }
  49.         }
  50. }