Title: The value of S=A+AA+AAA+AAAA+AA...A, where a is a number. For example 2+22+222+2222+22222 (there are 5 numbers added at this time), several numbers are added with keyboard control.
ImportJava.io.BufferedReader;Importjava.io.IOException;ImportJava.io.InputStreamReader;ImportJava.util.Scanner; Public classTestthree { Public Static voidMain (string[] args)throwsioexception{System.out.println ("Please enter the value of a"); BufferedReader BR=NewBufferedReader (NewInputStreamReader (system.in)); intA=Integer.parseint (Br.readline ()); System.out.println ("Please enter the number of B:"); BufferedReader buf=NewBufferedReader (NewInputStreamReader (system.in)); intb=Integer.parseint (Br.readline ()); /*Scanner sc = new Scanner (system.in); int a = Sc.nextint ();*/System.out.println ("Please enter a value for B");//int b = Sc.nextint (); ints=Count_value (b,a); System.out.println (s); }Private Static intCount_value (intIinta) { if(I <= 0) { return0; } Else { returnA * i + count_value (i-1,a) * 10; } }}
Knowledge Supplement: BufferedReader in Read () and ReadLine ()
Read ():
Method function: reads a single character.
Returns: The character that is read as an integer (its range from 0 to 65535 (0X00-0XFFFF)), that is, the ASCII code of type char . Returns 1 if the end of the stream has been reached.
ReadLine ():
Method function: Reads a line of text. A line is considered terminated by one of the following characters: line break (' \ n '), carriage return (' \ R '), or carriage return followed by line wrapping.
Returns: A string containing the contents of the row, with no line terminator, or null if the end of the stream has been reached
Java interview one question per day 3