0% found this document useful (0 votes)
31 views9 pages

Write A Program To Display Weekday.: Coding

The document provides code snippets for 6 Java programs: 1) Display weekday from number input, 2) Display Fibonacci series, 3) Reverse number, 4) Find greatest of 3 numbers, 5) Check if number is Armstrong number, 6) Not specified. For each, it shows the coding to implement the logic and sample output.

Uploaded by

Arun Pratap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views9 pages

Write A Program To Display Weekday.: Coding

The document provides code snippets for 6 Java programs: 1) Display weekday from number input, 2) Display Fibonacci series, 3) Reverse number, 4) Find greatest of 3 numbers, 5) Check if number is Armstrong number, 6) Not specified. For each, it shows the coding to implement the logic and sample output.

Uploaded by

Arun Pratap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Write a program to display weekday.

Coding:int num = Integer.parseInt(jTextField1.getText());


switch(num)
{
case 1:
jTextArea1.setText("Sunday");
break;
case 2:
jTextArea1.setText("Monday");
break;
case 3:
jTextArea1.setText("Tuesday");
break;
case 4:
jTextArea1.setText("Wednesday");
break;
case 5:
jTextArea1.setText("Thursday");
break;
case 6:
jTextArea1.setText("Friday");
break;
case 7:

jTextArea1.setText("Saturday");
break;
default:
jTextArea1.setText("Please enter a valid no. b/w 1 to 7 ");
}

Output:-

Write a program to display Fibonacci


series.

Coding:-

int a,b,c,i,n;
n = Integer.parseInt(jTextField1.getText());
a=1; b=1;
jTextArea1.append(""+a+"\t"+b);
for (i=1;i<=(n-2);i++)
{
c=a+b;
jTextArea1.append("\t"+c);
a=b;
b=c;

Output:-

Write a program to display reverse


no.

Coding:int i,a,digit,rev=0;
a= Integer.parseInt(jTextField1.getText());
for(i=a;i>=1;i=i/10)
{
digit=i%10;
rev=((rev+digit)*10);
}
jTextArea1.setText("The reverse no. is "+ rev/10);

Output:-

Write a program to display the


greatest of the three numbers.

Coding:int a= Integer.parseInt(jTextField1.getText());
int b= Integer.parseInt(jTextField2.getText());
int c= Integer.parseInt(jTextField3.getText());
if((a>b)&&(a>c))
jTextArea1.setText("The Gretest no. is" + a);
else if(b>c)
jTextArea1.setText("The Greatest no. is"+ b);
else
jTextArea1.setText("The Greatest no. is"+ c);

Output:-

Write a program to check whether a


number is Armstrong number or not.

Coding:-

int i,num,a,sum=0;
num= Integer.parseInt(jTextField1.getText());
for(i=num;i>=1;i=i/10)
{
a=i%10;
a=a*a*a;
sum+=a;
}
if(num==sum)
jTextArea1.setText("The Given number is an Armstrong Number");
else
jTextArea1.setText("The given number is not an Armstrong Number");

Output:-

You might also like