在文本上写文件时遇到问题.正如您所看到的,我曾经\n在下一行添加了另一组数据.问题是,当我关闭该文件,并再次保存与结束每行数据\n变得\n\n等等.这就是为什么我的文件看起来像这样
首先要保存
test, test, test
test, test, test
Run Code Online (Sandbox Code Playgroud)
第二个保存
test, test, test
test, test, test
Run Code Online (Sandbox Code Playgroud)
第三个保存
test, test, test
test, test, test
Run Code Online (Sandbox Code Playgroud)
这就是为什么当我在屏幕上显示它...之间有垃圾值...我的代码如下:
save(){
int i = 0;
FILE *stream = NULL;
stream = fopen("student.txt", "wt");
printf("\nSaving the student list directory. Wait a moment please...");
printf("\nExiting the program...");
for (i=0; i<recordCtr; i++){
fprintf(stream, "%s, %s, %s\n", array[i]->studentID, array[i]->name, array[i]->course);
}
}
Run Code Online (Sandbox Code Playgroud)
请帮助...任何建议将不胜感激.先感谢您.
美好的一天!
我是Java的初学者.我无法编译以下代码:
public class Test {
public static void main (String [] args ){
int a = calcArea(7, 12);
System.out.println(a);
}
int calcArea(int height, int width) {
return height * width;
}
}
Run Code Online (Sandbox Code Playgroud)
出现以下错误:
__CODE__
这是什么意思?我该如何解决这个问题..?
您的回复将受到高度赞赏.谢谢
根据您的建议,我创建了一个新的test()实例,如下所示:
public class Test {
int num;
public static void main (String [] args ){
Test a = new Test();
a.num = a.calcArea(7, 12);
System.out.println(a.num);
}
int calcArea(int height, int width) {
return height * width;
}
}
Run Code Online (Sandbox Code Playgroud)
它是否正确?如果我这样做有什么区别......
public class Test { …Run Code Online (Sandbox Code Playgroud) 关于我之前的问题,我现在遇到了一个新问题.为了避免内部类,我的类现在实现了一个actionListener.我的代码如下:
public class MainGame extends JDialog implements ActionListener {
public MainGame(JDialog owner) {
super(owner, true);
initComponents();
jPanel1.setLayout(new GridLayout(3, 9, 3, 5));
for (char buttonChar = 'a'; buttonChar <= 'z'; buttonChar++) {
String buttonText = String.valueOf(buttonChar);
letterButton = new JButton(buttonText);
letterButton.addActionListener(this);
jPanel1.add(letterButton);
}
newGame();
}
public void actionPerformed (ActionEvent action){
if (action.getSource() == letterButton) {
letterButton.setEnabled(false);
}
}
Run Code Online (Sandbox Code Playgroud)
如何影响我的按钮A到Z的监听器?因为它可以收听的是最后一个按钮,在这种情况下是按钮Z.
谢谢.
我的文字区域有问题.
我jTextArea1.append("cleverly amusing");用来添加文字..
第一个附件:

然后我jTextArea1.append("a fight");用来添加下一个文本.
第二个附件

我真正想要的是将"巧妙有趣"替换为"战斗".但我不能这样做.我尝试使用jTextArea1.removeAll();但没有效果.如何删除"巧妙有趣",以便我可以将"战斗"添加到第一行.
注意:"WORD HINT"是固定的......
我能做什么?
我怎么能转换这个:
Map<String, Integer> itemsBought
Run Code Online (Sandbox Code Playgroud)
所以我可以将它添加到ArrayList上,如下所示:
public void add(String prd, int qty){
orderList.add(new Order(prd, qty));
}
Run Code Online (Sandbox Code Playgroud)
除此之外还有其他解决方案:
hashMap.keySet().toArray();
hashMap.values().toArray();
Run Code Online (Sandbox Code Playgroud)
先感谢您.
有谁知道为什么tab(\ t)不能与JOptionPane.showMessageDialog一起使用?
我的代码如下:
String addText = "NAME\t\tADDRESS\t\tTEL.No\tEMAIL\n";
for (int i = 0; i < addressBookSize; i++) {
addText = addText+entry[i].viewAllInfo();
}
System.out.print(addText);
JOptionPane.showMessageDialog(null, addText);
Run Code Online (Sandbox Code Playgroud)
还有其他方法可以在JOptionPane中对齐文本吗?
我想按对象的值对Hashmap进行排序.在这种情况下,按国家/地区代码.
KEY OBJECT
String LoyaltyCountry
- country name
- country code
- country loc
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
public static HashMap<String, LoyaltyCountry> loyaltyCountrySortMap(HashMap<String, LoyaltyCountry> loyaltyCountryMap) {
if (loyaltyCountryMap != null) {
List keys = new ArrayList();
keys.addAll(loyaltyCountryMap.keySet());
Collections.sort(keys, new Comparator<LoyaltyCountry>() {
public int compare(LoyaltyCountry o1, LoyaltyCountry o2) {
return o1.getCountryName().compareTo(o2.getCountryName());
}
});
}
return loyaltyCountryMap;
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能正确?
我想将我的表的数据从一个表交换到另一个表中的同一列(注意:我只有两列).
我的问题是我无法交换价值.此外,我希望仅在同一列上启用交换,否则,表值将重置为其原始值.
这是我的代码:
JTable table_1 = new JTable(model);
table_1.setPreferredScrollableViewportSize(new Dimension(300, 120));
table_1.setDragEnabled(true);
table_1.setDropMode(DropMode.USE_SELECTION);
table_1.setTransferHandler(new TransferHelper());
table_1.setRowSelectionAllowed(false);
table_1.setCellSelectionEnabled(true);
Run Code Online (Sandbox Code Playgroud)
我的TransferHelper类:
class TransferHelper extends TransferHandler {
private static final long serialVersionUID = 1L;
public TransferHelper() {
}
@Override
public int getSourceActions(JComponent c) {
return MOVE;
}
@Override
protected Transferable createTransferable(JComponent source) {
String data = (String) ((JTable) source).getModel().getValueAt(((JTable) source).getSelectedRow(), ((JTable) source).getSelectedColumn());
return new StringSelection(data);
}
@Override
protected void exportDone(JComponent source, Transferable data, int action) {
((JTable) source).getModel().setValueAt("", ((JTable) source).getSelectedRow(), ((JTable) source).getSelectedColumn());
}
@Override …Run Code Online (Sandbox Code Playgroud) 我有以下exec查询:
EXEC (
'SELECT (SELECT Count(*) AS Count_Id FROM ns_customer WHERE external_id IN (
' RW00363075 ',' RW00336566 ',' RW00365438 ',' RW00343570 ') ) AS Count_Id,
ACH_allowed, CC_allowed, DD_allowed FROM ns_customer
WHERE external_id IN (' RW00363075 ',' RW00336566 ',' RW00365438 ',
' RW00343570 ')'
);
Run Code Online (Sandbox Code Playgroud)
执行后我收到一个错误:
SQL语句:'RW00363075'附近的语法不正确.引起:'RW00363075'附近的语法不正确.
我怎么解决这个问题?
谢谢