Challenge programming Programming Competition Training Manual-1.6.4 LCD display (LC-display)

Source: Internet
Author: User

Challenge programming Programming Competition Training Manual-1.6.4LCD screen(LC-display)

Public class problem_lc_display {/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stub/* For (int K = 0; k <10; k ++) {system. out. print ("|");} system. out. println (""); For (int K = 0; k <10; k ++) {system. out. print ("");} system. out. println (""); For (int K = 0; k <10; k ++) {system. out. print ("-");} system. out. println (""); * // The preceding Code verifies that the space distance of some fonts is short, which may lead to the display offset string n = "0123456789"; // The display content int S = 3; // display size // system. out. println (n); printnumber (N, S);}/* scan a row, judge the number once, and output the corresponding strokes according to the number and format, scan another line */Private Static void printnumber (string N, int s) {char [] num = n. tochararray (); For (INT line = 1; line <= (2 * s + 3); line ++) {// scan rows, of which 1st rows, row (S + 2), (2 * s + 3) behavior '-' // and the number of rows is fixed to (2 * s + 3) Row for (INT I = 0; I <num. length; I ++) {judgenum (Num [I], S, line); system. out. print (""); // The gap between each number} system. out. println ("") ;}}/* judge the number and enter Output */Private Static void judgenum (char num, int S, int line) {// todo auto-generated method stubint L = line; // The number of rows currently scanned/* The detailed algorithm of numbers can be found in Number 2 *. You can also write another method for unified calling to output numbers. The following code is for reference, write an algorithm for setting up the liquid crystal body for each number * call the output method Overview: * Get the current number of rows and then judge the number. * For example, in the first row, both 1 and 4 output spaces, while other numbers need to output spaces and "-" * control the output width and output characters based on the judgment result and input variable S. * And so on ...... */Switch (Num) {// select to judge the number case '0': {// 0-0if (L = 1) | (L = (2 * s + 3) {// | 0 | for (INT width = 1; width <= S + 2; width ++) {// 000if (width = 1) | (width = S + 2) {// | 0 | system. out. print (""); // 0-0} else {system. out. print ("-") ;}} else if (L = S + 2) {for (INT width = 1; width <= S + 2; width ++) {system. out. print ("") ;}} else {for (INT width = 1; width <= S + 2; width ++) {If (width = 1) | (width = S + 2) {system. out. print ("|");} else {system. out. print ("") ;}}} break; Case '1': {// 000if (L = 1) | (L = S + 2) | (L = (2 * s + 3) {// 00 | for (INT width = 1; width <= S + 2; width ++) {// 000system. out. print (""); // 00 |} // 000} else {for (INT width = 1; width <= S + 2; width ++) {If (width = S + 2) {system. out. print ("|");} else {system. out. print ("") ;}}} break; Case '2 ': {// 0-0 // 00 | // 0-0 // | 00 // 0-0 if (L = 1) | (L = S + 2) | (L = (2 * s + 3) {// determines whether the scan is performed on the first row and the middle row, and the last line // because these three rows must output "-" For (INT width = 1; width <= S + 2; width ++) {// for 2, if (width = 1) | (width = S + 2 )) {// If the loop is to the frontend and last, a space system is output. out. print ("");} else {// if it is in the middle, the system is output. out. print ("-") ;}}} else if (L <(S + 2) {// if it is not in the first row, the middle row, and the last row, in addition, if the number of rows is in the upper part, for (INT width = 1; width <= (S + 2); width ++) {// output width of loop 2 by format if (width = (S + 2) {// output "|" system. out. print ("|");} else {// The Rest Of The upper part is space system. out. print ("") ;}} else {// if it is not in the first line, the middle line, and the last line, and if the number of rows is in the lower half of 2, for (INT width = 1; width <= (S + 2); width ++) {If (width = 1) {// output "|" system. out. print ("|");} else {// the lower half and the rest all output space system. out. print ("") ;}}} break; Case '3 ': {// 0-0 // 00 | // 0-0 // 00 | // 0-0 if (L = 1) | (L = S + 2) | (L = (2 * s + 3) {for (INT width = 1; width <= (S + 2); width ++) {If (width = 1) | (width = (S + 2) {system. out. print ("");} else {system. out. print ("-") ;}}else {for (INT width = 1; width <= (S + 2); width ++) {If (width = (S + 2) {system. out. print ("|");} else {system. out. print ("") ;}}} break; Case '4': {If (L = S + 2) {for (INT width = 1; width <= (S + 2); width ++) {If (width = 1 | width = (S + 2) {system. out. print ("");} else {system. out. print ("-") ;}} else if (L = 1 | L = 2 * s + 3) {for (INT width = 1; width <= (S + 2); width ++) {system. out. print ("") ;}} else if (L <S + 2) {for (INT width = 1; width <= (S + 2); width ++) {If (width = 1 | width = S + 2) {system. out. print ("|");} else {system. out. print ("") ;}}} else if (L <2 * s + 3) {for (INT width = 1; width <= S + 2; width ++) {If (width = S + 2) {system. out. print ("|");} else {system. out. print ("") ;}}} break; Case '5 ': {// 0-0 // | 00 // 0-0 // 00 | // 0-0 if (L = 1) | (L = S + 2) | (L = (2 * s + 3) {for (INT width = 1; width <= S + 2; width ++) {If (width = 1) | (width = S + 2) {system. out. print ("");} else {system. out. print ("-") ;}}} else if (L <(S + 2) {for (INT width = 1; width <= (S + 2 ); width ++) {If (width = 1) {system. out. print ("|");} else {system. out. print ("") ;}}} else if (L <(2 * s + 3) {for (INT width = 1; width <= (S + 2 ); width ++) {If (width = (S + 2) {system. out. print ("|");} else {system. out. print ("") ;}}} break; Case '6 ': {// 0-0 // | 00 // 0-0 // | 0 | // 0-0 if (L = 1) | (L = S + 2) | (L = (2 * s + 3) {for (INT width = 1; width <= S + 2; width ++) {If (width = 1) | (width = S + 2) {system. out. print ("");} else {system. out. print ("-") ;}}} else if (L <(S + 2) {for (INT width = 1; width <= (S + 2 ); width ++) {If (width = 1) {system. out. print ("|");} else {system. out. print ("") ;}}else {for (INT width = 1; width <= (S + 2); width ++) {If (width = (S + 2) | (width = 1) {system. out. print ("|");} else {system. out. print ("") ;}}} break; Case '7 ': {// 0-0 // 00 | // 000 // 00 | // 000if (L = S + 2) | (L = (2 * s + 3) {for (INT width = 1; width <= S + 2; width ++) {system. out. print ("") ;}} else if (L = 1) {for (INT width = 1; width <= S + 2; width ++) {If (width = 1 | width = S + 2) {system. out. print ("");} else {system. out. print ("-") ;}}else {for (INT width = 1; width <= S + 2; width ++) {If (width = S + 2) {system. out. print ("|");} else {system. out. print ("") ;}}} break; Case '8 ': {// 0-0 // | 0 | // 0-0 // | 0 | // 0-0 if (L = 1) | (L = S + 2) | (L = (2 * s + 3) {for (INT width = 1; width <= S + 2; width ++) {If (width = 1) | (width = S + 2) {system. out. print ("");} else {system. out. print ("-") ;}}else {for (INT width = 1; width <= (S + 2); width ++) {If (width = 1 | width = (S + 2) {system. out. print ("|");} else {system. out. print ("") ;}}} break; Case '9 ': {// 0-0 // | 0 | // 0-0 // 00 | // 0-0 if (L = 1) | (L = S + 2) | (L = (2 * s + 3) {for (INT width = 1; width <= S + 2; width ++) {If (width = 1) | (width = S + 2) {system. out. print ("");} else {system. out. print ("-") ;}}} else if (L <(S + 2) {for (INT width = 1; width <= (S + 2 ); width ++) {If (width = (S + 2) | width = 1) {system. out. print ("|");} else {system. out. print ("") ;}}else {for (INT width = 1; width <= (S + 2); width ++) {If (width = (S + 2) {system. out. print ("|");} else {system. out. print ("") ;}}} break; default: Break ;}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.