lunes, 23 de abril de 2007

hallar el MCD

/*
* UsoWhile.java
*
* Created on 17 de abril de 2007, 07:49 PM
*/

/**
*
* @author ALUMNO
*/
public class UsoWhile extends javax.swing.JFrame {

/** Creates new form UsoWhile */
public UsoWhile() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTextPane1 = new javax.swing.JTextPane();
jScrollPane2 = new javax.swing.JScrollPane();
jTextPane2 = new javax.swing.JTextPane();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jScrollPane3 = new javax.swing.JScrollPane();
jTextPane3 = new javax.swing.JTextPane();
jScrollPane4 = new javax.swing.JScrollPane();
jTextPane4 = new javax.swing.JTextPane();
jScrollPane5 = new javax.swing.JScrollPane();
jTextPane5 = new javax.swing.JTextPane();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();


setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jScrollPane1.setViewportView(jTextPane1);

jScrollPane2.setViewportView(jTextPane2);

jLabel1.setText("1er numero");

jLabel2.setText("2do Numero");

jScrollPane3.setViewportView(jTextPane3);

jScrollPane4.setViewportView(jTextPane4);

jScrollPane5.setViewportView(jTextPane5);

jLabel3.setText("MCD");

jLabel4.setText("N1");

jLabel5.setText("N2");

jButton1.setText("Evalua");
jButton1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton1ActionPerformed(evt);
}
});

org.jdesktop.layout.GroupLayout layout = new
org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING,
false)
.add(layout.createSequentialGroup()
.add(30, 30, 30)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel1)
.add(jLabel2))
.add(14, 14, 14))

.add(org.jdesktop.layout.GroupLayout.TRAILING,
layout.createSequentialGroup()

..addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.add(jLabel3)
.add(23, 23, 23)))

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane5,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 65,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING,
false)

..add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane2)

..add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)))

..addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 32,
Short.MAX_VALUE)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel4)
.add(jScrollPane3,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 89,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(20, 20, 20)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel5)
.add(jScrollPane4,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 82,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(layout.createSequentialGroup()
.add(150, 150, 150)
.add(jButton1)))
.addContainerGap())
);
layout.setVerticalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jLabel1)
.add(jScrollPane1,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

..addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jScrollPane2,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel2))
.add(54, 54, 54)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jScrollPane5,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel3)))
.add(layout.createSequentialGroup()
.add(46, 46, 46)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel4)
.add(jLabel5))

..addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane3,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 116,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jScrollPane4,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE))))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED,
40, Short.MAX_VALUE)
.add(jButton1)
.add(55, 55, 55))
);
pack();
}//
//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent
evt)
{//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
int A,B, r, MCD;
String strMCD, strA, strB;
A = Integer.parseInt(jTextPane1.getText());
B = Integer.parseInt(jTextPane2.getText());

strA = ""; strB = "";
while(B!=0){
strA += String.valueOf(A)+ "\n";
strB += String.valueOf(B)+ "\n";
r = A % B;
A = B;
B = r;
}
strA += String.valueOf(A)+ "\n";
strB += String.valueOf(B)+ "\n";
jTextPane3.setText(strA);
jTextPane4.setText(strB);
MCD = A;
strMCD = String.valueOf(MCD);
jTextPane5.setText(strMCD);
}//GEN-LAST:event_jButton1ActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new UsoWhile().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JTextPane jTextPane1;
private javax.swing.JTextPane jTextPane2;
private javax.swing.JTextPane jTextPane3;
private javax.swing.JTextPane jTextPane4;
private javax.swing.JTextPane jTextPane5;
// End of variables declaration//GEN-END:variables

}

No hay comentarios: