Java interview one question per day 3

Source: Internet
Author: User

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

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.