Computer Science, asked by Ayush0009, 1 year ago

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.


Anonymous: please ask both of the question separately
Anonymous: state one example also
Ayush0009: I know the answer
Ayush0009: plz give
Ayush0009: plz give me the answer
Anonymous: plz explain 2nd question
Anonymous: ??

Answers

Answered by Anonymous
2

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);

}

}



Anonymous: toh comment section mei puch dena
Anonymous: tumhare pass points kam hai
Ayush0009: pata hai
Ayush0009: Maine aur foo program post kiya hai
Ayush0009: tummy Delhi lena
Anonymous: delhi lena?
Anonymous: u mean dekh lena?
Ayush0009: sorry dekh lena
Anonymous: theek hai , 6 baje tak sare answer , likh dunga
Anonymous: dont worry
Answered by phillipinestest
3

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"

Similar questions