Write a program in java to accept a five digit number and display the sum, average and absolute difference of first and last digit of that number with proper message.
WAP in java to accept the day value and convert the day value in year, month, week and day form. Display the result with proper message.
please answer me to these two questions properly.
Answers
import java.io.*;
public class Fivedigit
{
public static void main () throws IOException
{
int n;
DataInputStream di =new DataInputStream (System.in);
System.out.println("Enter any five digit number");
n=Integer.parseInt(di.readLine());
int u = n%10;
int f= n/10000;
int sum = u + f ;
int avg = sum/2;
int diff= u-f;
if(u<f)
System.out.println("Absolute difference =" +(-1*diff));
else
System.out.println("Absolute difference =" +diff);
System.out.println("Sum=" + sum);
System.out.println("Average="+avg);
}
}
The program is as follows:
import java.io.*;
public class calc
{
public static void main () throws IOException
{
int n;
DataInputStream di =new DataInputStream (System.in);
System.out.println("Enter any five digit number");
n=Integer.parseInt(di.readLine());
int u = n%10;
int f= n/10000;
int sum = u + f ;
int avg = sum/2;
int diff= u-f;
if(u<f)
System.out.println("Absolute difference =" +(-1*diff));
else{
System.out.println("Absolute difference =" +diff);
System.out.println("Sum=" + sum);
System.out.println("Average="+avg);
}
}
}
By making this program to run, the output will be:
i) it will give the sum of the first and last digits of the provided 5 digit number.
ii) the difference in the first and last digits
iii) average of the first and last digits"