java 打印的缩写_如何创建一个打印姓氏和首字母缩写Java的程序? [等候接听]

目前我正在尝试编写一个可以从文件中获取多个名称并重新排列它们的程序 .

输入:

marry brady

harold mackenzie

karthik kanagasabathy

juri huddler

magic johnson

fred jones

tony ng

alfonzo camazinavichuk

herman goring

herbert milfons

annie li

samantha choorizoonanni

deb lee

然后,我想要在格式良好的单个框中输出它们 .

* * * * * * * *

* brady, m *

* * * * * * * *

* * * * * * * *

* harold, m *

* * * * * * * *

等等...

我试图通过创建一个 stripSpace() 方法,一个名为 formal 的方法来重新排列名称,最后 show 来在框中显示名称 .

我的代码未完成,我正在努力创建show方法,将名称放在格式良好的框中 .

我设法扭转这些名字,以便他们现在而不是说,george clooney他们现在是clooney,乔治,但我希望他们是clooney,g .

到目前为止这是我的代码:

import java.io.*;

public class MethodsAssignment {

public static void main(String[] args) throws IOException {

File file = new File("//Users//Desktop//names copy.txt");

FileInputStream fileStream = new FileInputStream(file);

InputStreamReader input = new InputStreamReader(fileStream);

BufferedReader reader = new BufferedReader(input);

String line;

String fixedWords;

String finalList;

line = reader.readLine();

while (line != null) {

fixedWords = stripSpace(line);

finalList = formal(fixedWords);

show(finalList);

line = reader.readLine();

}

}

public static String stripSpace(String name) {

String spaceless = name.trim();

return spaceless;

}

public static String formal(String name) {

String firstName = name.substring(0, name.indexOf(" ")); //write the frm 0 a la space

String lastName = name.substring(name.indexOf(" ") + 1);// from one after the space ONWARDS

String cName = lastName + ", " + firstName;

return cName;

}

public static void show (String list) {

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值