a program asking the user to unscramble the scrambled word
TRANSCRIPT
1. A program asking the user to unscramble the scrambled word.
FRAME:
CODING:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
char s;
String sword, nword;
int i=0,l,j,k;
t1.setText("");
t2.setText("");
sword=t3.getText();
l=sword.length();
if(l%3==0)
{k=2;}
else
{k=3;}
while(t1.getText().length()<=l)
{s=sword.charAt(i);
t1.setText(t1.getText() + s);
i+=k;
if(i>l)
{i=i-l;
}
}
for(j=0; j<=50; j++)
{l1.setSelectedIndex(j);
nword=(String)l1.getSelectedValue();
if( nword.equals(sword))
{l1.setSelectedIndex(j+1);
t4.setText((String)l1.getSelectedValue());
}
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int i,j;
String s,t;
t=t2.getText();
for(i=0; i<=20; i++)
{l1.setSelectedIndex(i);
s=(String)l1.getSelectedValue();
if(s.equals(t3.getText()))
{break;}
}
l1.setSelectedIndex(i-1);
s=(String)l1.getSelectedValue();
if(t.equals(s))
{JOptionPane.showMessageDialog(null, "You are Great. You are right at your point");}
else
{JOptionPane.showMessageDialog(null, "You Lose. You got to learn more.");}
}
RUN-TIME VIEW:
On Clicking New Word(jButton2):
On clicking Guess(jButton 2):
In case , the answer is right:
In case the answer is wrong:
On again clicking New Word(jButton2):
2. A program to check the number of occurrence of every alphabet before it.
FRAME:
CODING:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int c, l;
char a, ch;
String w,m;
t2.setText("");
w=t1.getText();
l=w.length();
for(int i=0; i<=l; i++)
{c=0;
a=w.charAt(i);
for(int j=i; j<=l; j++)
{if(w.charAt(j) == a)
{c++;
}
t2.append(w.charAt(j) + "-" + c + "\n");
}
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
t1.setText(null);
t2.setText(null);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
RUN-TIME VIEW:
3. A program to print the number as a product of prime factors.
CODING:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int n,r=0,p,a;
n=Integer.parseInt(t1.getText());
a=n;
ta1.append(n + "=");
for(int i=2; i<=n; i++)
{p=0;
for(int j=1; j<=i; j++)
{if(i%j==0)
{p++;
r=i;
}
}
if(p==2)
{while(a%r==0)
{a=a/r;
ta1.append(r + "x");
}
}
}ta1.append("1" + "\n");
}
RUN-TIME VIEW:
4. A program to find the abundant numbers between the given two numbers.
FRAME:
CODING
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int s;
for(int i=Integer.parseInt(t1.getText()); i<=Integer.parseInt(t2.getText()); i++)
{s=0;
for(int j=2; j<=i; j++)
{if(i%j==0)
{s=s+j;
}
}
if(s>i+i)
{ta1.append(i + "\n");
}
}
}
RUN-TIME VIEW:
5. A program to check whether the number is a Kaprekar Number.
FRAME:
CODING:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int n,a,m=0;
n=Integer.parseInt(t1.getText());
a=n*n;
while(a!=0)
{m=m+(a%10);
a/=10;
}
if(m==a)
{JOptionPane.showMessageDialog(null, "This is a Kaprekar Number.");
}
else
{ JOptionPane.showMessageDialog(null, "No. This is not a Kaprekar Number.");}
}
RUN_TIME VIEW: