NDROID TECH
  • Home (current)
  • Blog
  • About
  • Categories
    Entertainment
    Technology
    Programming
    Android
    Web Development
    Games
    Ethical Hacking
    motivational
  • Contact
  • Privacy Policy
  • Terms of Use
  1. Home
  2. Blog
image not available
  • 2020-03-24
  • admin
  • NPTEL,SWAYAM,JAVA,Programming
  • 418

NPTEL WEEK 8 Q 5 : JAVA Programming Solution 2020



Share :

Java Week 8: Q5

Due on 2020-03-26, 23:59 IST
Write a program to display any digit(n) from 0-9 using "7 segment  display". 

For example:

input : 5

output :
 _ 
|_ 
 _|

input : 4

output :

|_|
   |


Note: Spaces must be exactly same as in the example for correct evaluation. 

Select the Language for this assignment.
File name for this program :

import java.util.*;

public class Pattern5 {

   private static final Map<Integer, Integer> encodings =

        new HashMap<Integer, Integer>();

​

    static {

        encodings.put(0, 0x7E);

        encodings.put(1, 0x30);

        encodings.put(2, 0x6D);

        encodings.put(3, 0x79);

        encodings.put(4, 0x33);

        encodings.put(5, 0x5B);

        encodings.put(6, 0x5F);

        encodings.put(7, 0x70);

        encodings.put(8, 0x7F);

        encodings.put(9, 0x7B);

    }

​

    public static void printDigit(int digit) {

        int code = encode(digit);

        char[] bits =

            String.format("%7s", Integer.toBinaryString(code))

                .replace(' ', '0').toCharArray();

​

        lightSegment(bits[0] == '1', " _ \n", "   \n");

        lightSegment(bits[5] == '1', "|", " ");

        lightSegment(bits[6] == '1', "_", " ");

        lightSegment(bits[1] == '1', "|\n", " \n");

        lightSegment(bits[4] == '1', "|", " ");

        lightSegment(bits[3] == '1', "_", " ");

        lightSegment(bits[2] == '1', "|\n", " \n");

    }

​

    private static void lightSegment(boolean on, String onValue, String offValue) {

        System.out.print(on ? onValue : offValue);

        try {

            Thread.sleep(0);

        }

        catch (InterruptedException e) {

            e.printStackTrace();

        }

    }

​

    private static int encode(int digit) {

        return encodings.containsKey(digit) ? encodings.get(digit) : 0x00;

    }

   public static void main(String[] args) throws Exception {

           Scanner inr = new Scanner(System.in);

          int n = inr.nextInt();

           // Add the necessary code in the below space   

        printDigit(n);

       

    }

}

​


Categories

  • Entertainment 3
  • Technology 14
  • Programming 9
  • Android 11
  • Web Development 5
  • Games 14
  • Ethical Hacking 3
  • motivational 2


Stay Connected

  • Twitter
  • Facebook
  • Dribble
  • Pinterest


Editor's Choice

fantastic cms
Now ट्रैक कर सकेंगे कोरोना वायरस की जानकारी !!!
2020-03-22
fantastic cms
Whatsapp यह है खास फीचर| यूजर्स मैसेज की कर पाएंगे जांच !!!!!
2020-03-23


fantastic cms
सोशल मीडिया प्लेटफॉर्म से इन्हें हटाने के निर्देश : IT मंत्रालय सख्त
2018-04-27
fantastic cms
Benefits of WhatsApp ????
2018-04-27


fantastic cms
The future of वेब डिजाइनिंग on earth
2018-04-27
fantastic cms
Computer Science Projects and ideas for Engineering students as well as interested students.
2018-04-27


NDROID TECH

This is a ndroid.tech is related to technology blog. since active from 2018

About Us

Popular Posts

fantastic cms
How Corona effected on technology ???
2020-03-21
fantastic cms
How to activate windows 10 using CMD or batch file
2020-06-01

Signup to our newsletter

We respect your privacy.No spam ever!

  • Facebook
  • Twitter
  • Google+
  • Pinterest

ndroid tech 2021 | Brought To You by ndroid.tech