-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmstrongan.java
More file actions
53 lines (51 loc) · 1 KB
/
Copy pathArmstrongan.java
File metadata and controls
53 lines (51 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
/*<applet code="Armstrongan" width=500 height=500> </applet> */
public class Armstrongan extends Applet implements ActionListener
{
Label l1;
TextField t1,t2;
Button b1;
public void init()
{
l1=new Label("Enter a number: ");
t1=new TextField(10);
t2=new TextField(10);
b1=new Button("Check");
setLayout(null);
t2.setBounds(130,50,200,20);
add(t2);
t1.setBounds(230,100,120,20);
add(t1);
l1.setBounds(100,100,120,20);
add(l1);
b1.setBounds(100,120,40,20);
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String num1=t1.getText();
int num,r,s=0,temp;
String str1="Armstrong number";
String str2="Not armstrong number";
num=Integer.parseInt(num1);
for(temp=num;num!=0;num=num/10)
{
r=num%10;
s=s+(r*r*r);
}
if(ae.getSource()==b1)
{
if(s==temp)
{
t2.setText(str1);
}
else
{
t2.setText(str2);
}
}
}
}