You are on page 1of 4

1.

WAP TO DSPL ALL EVEN NO B/W ONE -100


ANS.-----

int a;
int c=0;
for(a=2;a<=100;a=a+2)
{
if (c==10)
{
c=0;
jTextArea1.append("\n");
}
jTextArea1.setText(jTextArea1.getText()+" "+a);
c=c+1;
}

2.WAP to dsply all odd no b/w 100 to one.?


ANS----

int a;
int c=0;
for(a=99;a>=1;a=a-2)
{
if (c==10)
{
c=0;
jTextArea1.append("\n");
}
jTextArea1.setText(jTextArea1.getText()+" "+a);
c=c+1;
}

3.WAP to input any no and check whether it is 4 digit number or not.


ANS.----int a=Integer.parseInt(jTextField1.getText());
if(a>=1000 && a<=9999)
jLabel2.setText(a+" is a FOUR digit Number");
else
jLabel2.setText(a+" is not a FOUR digit number");
}

4.WAP to input any number and check whether it is Prime number or not
ANS. int a=Integer.parseInt(jTextField1.getText());
int i,f;
f=0;
for(i=2;i<=a-1;i++)
{
if(a %i==0)
f=1;
}
if(f==0)
jLabel2.setText("Number is prime");
else
jLabel2.setText("number is not prime");
}

5.WAP to input any year and check whether it is leap year or not
ANS. int a=Integer.parseInt(jTextField1.getText());
if( a % 4 ==0)
jLabel2.setText(a + " is a leap year");
else
jLabel2.setText(a + " is not a leap year");
}

Screen shots………
Ques 1

Ques 2
Ques 3

Ques 4.

Ques 5
6Wap to input a numbe r and display its fatorial
7Wap to input x and y and display x to the power of y

You might also like