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