开发者

Appending something to the result of scan.next() in Java

I have

String add_data[] = new String[6];

then I do

System.out.println("COMPANY NAME: ");
add_data[0] = scan.next();

I need to append a character to what to get from scan.next() & put that into add_data[0]. Please guide me how to accom开发者_如何学编程plish this task.


Assuming scan refers to java.util.Scanner this can be accomplished easily:

add_data[0] = scan.next() + 'c';


Let's use a well-named function.

public String nextLine(Scanner aInputStream) {
    return (aInputStream.next() + 'x');
}

add_data[0] = nextLine(new Scanner());

Well free to tuck that Scanner parameter into the function as a local variable if it bothers you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜