New features of the "Programming Questions" calculator

Source: Internet
Author: User

Title: New Features of calculator

Attach the Java version of the Code submitted

Title Description

When you learn some visual programming language, the teacher will often let you design and programming to make a calculator, then perhaps you will imitate the Windows system comes with the appearance and function of the calculator to design, but now the teacher wants you to make a new function of the calculator, implementation when entering a number, This number can be decomposed into the form of a product of one or more element factors and displayed by the size of the element factor. Everyone should be very clear about the number of calculators in the expression. The following shows a representation of 0-9 of these 10 numbers. Each number occupies 5 * 3 of the size of the character area


Can you implement this new feature? Try it!

1 Importjava.util.ArrayList;2 Importjava.util.List;3 ImportJava.util.Scanner;4 5  Public classComputer {6 7      Public Static voidMain (string[] args) {8Scanner input =NewScanner (system.in);9          while(Input.hasnextint ()) {Ten             intn =input.nextint (); OneList deposelist =despose (n); A //System.out.println (deposelist); - Printresult (deposelist); -         } the     } -  -     Private Static voidPrintresult (List deposelist) { -         intNumber =deposelist.size (); +String[] line1 = {"-", "", "-", "-", "", "-", "-", "-", "-", "-"}; -String[] line2 = {"| |", "|", "|", "|", "| |", "|  ","| ","  |","| |","| |"}; +String[] Line3 = {"", "", "-", "-", "-", "-", "-", "", "-", "-"}; AString[] line4 = {"| |", "|", "| ","  |","  |","  |","| |","  |","| |","  |"}; atString[] Line5 = {"-", "", "-", "-", "", "-", "-", "", "-", "-"}; -StringBuffer printLine1 =NewStringBuffer (); -StringBuffer PrintLine2 =NewStringBuffer (); -StringBuffer PrintLine3 =NewStringBuffer (); -StringBuffer printLine4 =NewStringBuffer (); -StringBuffer PrintLine5 =NewStringBuffer (); in          for(inti = 0; I < number; i++){ -String Stringnum =Deposelist.get (i). toString (); to //System.out.println (stringnum); +              for(intj = 0; J<stringnum.length (); J + +){ -Printline1.append (Line1[stringnum.charat (j)-' 0 ']); thePrintline2.append (Line2[stringnum.charat (j)-' 0 ']); *Printline3.append (Line3[stringnum.charat (j)-' 0 ']); $Printline4.append (Line4[stringnum.charat (j)-' 0 ']);Panax NotoginsengPrintline5.append (Line5[stringnum.charat (j)-' 0 ']); -             } thePrintline1.append (""); +Printline2.append (""); APrintline3.append ("*"); thePrintline4.append (""); +Printline5.append (""); -         } $         intPrintlen =printline1.length (); $Printline1.deletecharat (printLen-1); -Printline2.deletecharat (printLen-1); -Printline3.deletecharat (printLen-1); thePrintline4.deletecharat (printLen-1); -Printline5.deletecharat (printLen-1);Wuyi System.out.println (printLine1); the System.out.println (printLine2); - System.out.println (printLine3); Wu System.out.println (printLine4); - System.out.println (printLine5); About     } $  -     Private StaticList Despose (intN) { -List deposelist =NewArrayList (); -         intPrimer = 2; A          while(Primer <=N) { +             if(Primer = =N) { the Deposelist.add (primer); -                  Break; $             } the             Else if(n% Primer = = 0){ the Deposelist.add (primer); then = n/Primer; the             } -             Else{ inprimer++; the             }     the         } About         returndeposelist; the          the     } the  +}

Have a better idea, welcome to the advice ~

New features of the "Programming Questions" calculator

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.