J'ai ce programme en Java import java.util. *;J'ai besoin d'aide dans mon programme
public class Euclid {
private static final String EXCEPTION_MSG =
"Invalid value (%d); only positive integers are allowed. ";
public static int getGcd(int a, int b)
{
if (a < 0)
{
throw new IllegalArgumentException(String.format(EXCEPTION_MSG, a));
}
else
if (b < 0)
{
throw new IllegalArgumentException(String.format(EXCEPTION_MSG, b));
}
while (b != 0)
{
if (a > b)
{
a = a - b;
}
else
{
b = b - a;
}
}
return a;
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class EuclidGui
{
private static final String PROMPT_A = "#1";
private static final String PROMPT_B = "#2";
private static final String BUTTON_TEXT = "Get GCD >>";
private static final String EXCEPTION_TITLE = "Input Exception";
private static final String INSTRUCTIONS = "Type to integer and press 'Get GCD'";
private static final String DIALOG_TITLE = "Euclid's Algorithm";
private static final int FIELD_WIDTH = 6;
public static void main (String[] args)
{
final JTextField valueA = new JTextField (FIELD_WIDTH);
final JTextField valueB = new JTextField (FIELD_WIDTH);
final JTextField valueGcd = new JTextField (FIELD_WIDTH);
JLabel labelA = new JLabel(PROMPT_A);
JLabel labelB = new JLabel(PROMPT_B);
JButton computeButton = new JButton(BUTTON_TEXT);
Object[] options = new Object[] {labelA, valueA, labelB, valueB, computeButton, valueGcd};
valueGcd.setEditable (false);
computeButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{ try
{
int a = Integer.parseInt(valueA.getText());
int b = Integer.parseInt(valueB.getText());
int gcd = Euclid.getGcd(a , b);
valueGcd.setText(Integer.toString(gcd));
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage(), EXCEPTION_TITLE, JOptionPane.ERROR_MESSAGE);
}
}
});
JOptionPane.showOptionDialog(null, INSTRUCTIONS, DIALOG_TITLE, JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, null);
}
}
et je veux ajouter un code de temps de calcul sur elle, mais je ne sais pas comment, et quel est le code exact que je use.Please me aider si quelqu'un a une idée.
Veuillez mettre en retrait tout le code pour que tout apparaisse comme du code. – gdj
Que voulez-vous dire par «code temporel»? –