我有一个程序在循环中构建一个字符串,我的程序太慢了.现在需要大约600毫秒才能运行Oblig1Test.oppgave7.有什么办法可以加快速度?
Oblig1.toString:
public static String toString(int[] a, char v, char h, String mellomrom)
{
String s ="";
s += v;
if(a.length != 0)
{
for(int i = 0; i < a.length-1; i++)
{
s += a[i] + mellomrom;
}
s += a[a.length-1];
}
s += h;
return s;
}
Run Code Online (Sandbox Code Playgroud)
Oblig1Test:
public static int oppgave7()
{
int[] b = new int[20000];
long tid = System.currentTimeMillis();
Oblig1.toString(b,' ',' '," ");
tid = System.currentTimeMillis() - tid;
if (tid > 40) …Run Code Online (Sandbox Code Playgroud) 这段代码有点问题.该actionPerformed方法不起作用.按钮knappStartSalg和knappStartKunde,当我按动按钮没有反应.
应该导入的所有内容都是导入的.
非常感谢任何帮助.
开始上课.
public class Startmeny extends JFrame implements ActionListener
{
public JButton knappStartSalg, knappStartKunde, knappStartInfo, knappStartStatistikk;
public JPanel startmeny()
{
JPanel startpanel = new JPanel();
startpanel.setLayout(new GridLayout(2, 0, 25, 25) );
startpanel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
startpanel.setBackground(Color.white);
JButton knappStartSalg = new JButton();
knappStartSalg.setText("Salg");
knappStartSalg.setVerticalTextPosition(JButton.BOTTOM);
knappStartSalg.setHorizontalTextPosition(JButton.CENTER);
knappStartSalg.setIcon(new javax.swing.ImageIcon(getClass().getResource("salg.png")));
knappStartSalg.setIconTextGap(6);
knappStartSalg.setForeground(Color.black);
knappStartSalg.setBackground(Color.white);
knappStartSalg.setBorderPainted(false);
knappStartSalg.addActionListener(this);
startpanel.add(knappStartSalg);
JButton knappStartKunde = new JButton();
knappStartKunde.setText("Kontroll");
knappStartKunde.setVerticalTextPosition(JButton.BOTTOM);
knappStartKunde.setHorizontalTextPosition(JButton.CENTER);
knappStartKunde.setIcon(new javax.swing.ImageIcon(getClass().getResource("heiskontroll.png")));
knappStartKunde.setIconTextGap(6);
knappStartKunde.setForeground(Color.black);
knappStartKunde.setBackground(Color.white);
knappStartKunde.setBorderPainted(false);
knappStartKunde.addActionListener(this);
startpanel.add(knappStartKunde);
JButton knappStartInfo = new JButton();
knappStartInfo.setText("Informasjonsvindu");
knappStartInfo.setVerticalTextPosition(JButton.BOTTOM); …Run Code Online (Sandbox Code Playgroud)