JAVA_CODINGS Telegram 79
59. Middle value of an array.

import java.util.*;

class MiddleValue
{
public static void main(String args[])
{
int[] a;
int i, j, n, sum = 0, swap, size;

double t;
Scanner sc = new Scanner(System.in);

System.out.println("Enter size of array");
size = sc.nextInt();

a = new int[size];

System.out.println("Enter numbers ");
for (i = 0; i < size; i++)
{
a[i] = sc.nextInt();
}

System.out.println("Numbers are : ");
for (i = 0; i < size; i++)
{
System.out.print(a[i] + " ");
}

//Sorting
for (i = 0; i < (size - 1); i++)
{
for (j = 0; j < (size - i - 1); j++)
{
if (a[j] > a[j + 1])
{
swap = a[j];
a[j] = a[j + 1];
a[j + 1] = swap;
}
}
}

System.out.println("\nNumbers in sorted order : ");
for (i = 0; i < size; i++)
{
System.out.print(a[i] + " ");
}

//Finding the Middle Value
if (size % 2 == 0)
{
n = (size + 1) / 2;
t = (a[n] + a[n - 1]) / 2.0;
System.out.println("\nMiddle Value is : " + t);
}

else
{
System.out.println("\nMiddle Value is : " + a[size / 2]);
}

}
}

@java_codings



tgoop.com/java_codings/79
Create:
Last Update:

59. Middle value of an array.

import java.util.*;

class MiddleValue
{
public static void main(String args[])
{
int[] a;
int i, j, n, sum = 0, swap, size;

double t;
Scanner sc = new Scanner(System.in);

System.out.println("Enter size of array");
size = sc.nextInt();

a = new int[size];

System.out.println("Enter numbers ");
for (i = 0; i < size; i++)
{
a[i] = sc.nextInt();
}

System.out.println("Numbers are : ");
for (i = 0; i < size; i++)
{
System.out.print(a[i] + " ");
}

//Sorting
for (i = 0; i < (size - 1); i++)
{
for (j = 0; j < (size - i - 1); j++)
{
if (a[j] > a[j + 1])
{
swap = a[j];
a[j] = a[j + 1];
a[j + 1] = swap;
}
}
}

System.out.println("\nNumbers in sorted order : ");
for (i = 0; i < size; i++)
{
System.out.print(a[i] + " ");
}

//Finding the Middle Value
if (size % 2 == 0)
{
n = (size + 1) / 2;
t = (a[n] + a[n - 1]) / 2.0;
System.out.println("\nMiddle Value is : " + t);
}

else
{
System.out.println("\nMiddle Value is : " + a[size / 2]);
}

}
}

@java_codings

BY Advance Java πŸ‘¨β€πŸ’»


Share with your friend now:
tgoop.com/java_codings/79

View MORE
Open in Telegram


Telegram News

Date: |

Telegram channels enable users to broadcast messages to multiple users simultaneously. Like on social media, users need to subscribe to your channel to get access to your content published by one or more administrators. In the next window, choose the type of your channel. If you want your channel to be public, you need to develop a link for it. In the screenshot below, it’s ”/catmarketing.” If your selected link is unavailable, you’ll need to suggest another option. "Doxxing content is forbidden on Telegram and our moderators routinely remove such content from around the world," said a spokesman for the messaging app, Remi Vaughn. Hashtags are a fast way to find the correct information on social media. To put your content out there, be sure to add hashtags to each post. We have two intelligent tips to give you: Find your optimal posting schedule and stick to it. The peak posting times include 8 am, 6 pm, and 8 pm on social media. Try to publish serious stuff in the morning and leave less demanding content later in the day.
from us


Telegram Advance Java πŸ‘¨β€πŸ’»
FROM American