0% found this document useful (0 votes)
3 views1 page

Balanced Position Algorithm

The document outlines the Balanced Position Algorithm, which identifies a balanced index in an array where the sum of elements on either side is equal, with specific steps for input validation and processing. It also includes a Java program that checks if a given positive integer consists of distinct prime digits (2, 3, 5, 7). If the conditions are not met, appropriate error messages are displayed.

Uploaded by

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

Balanced Position Algorithm

The document outlines the Balanced Position Algorithm, which identifies a balanced index in an array where the sum of elements on either side is equal, with specific steps for input validation and processing. It also includes a Java program that checks if a given positive integer consists of distinct prime digits (2, 3, 5, 7). If the conditions are not met, appropriate error messages are displayed.

Uploaded by

ataabbaskhan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Balanced Position Algorithm

STEP 1: Input a [Link] 2: Input size of the array [Link] 3: Check whether N lies between 3 and [Link] not, print "INVALID SIZE" and go to STOP.
STEP 4: Create an integer array ARR of size [Link] 5: Input the N elements into [Link] 6: Initialise LSUM = 0 and RSUM = [Link] 7: Repeat steps for each
index [Link] 8: Initialise LSUM with the sum of elements before index [Link] 9: Initialise RSUM with sum of elements after index [Link] 10: Check IF LSUM ==
[Link] yes → go to STEP [Link] no → increase I by 1 and go back to STEP [Link] 11: Print value of I (Balanced point).STEP 12: Increment I by 1 and repeat until I
becomes [Link] 13: If no index satisfies the condition, print “NONE”.STEP 14: STOP.

import [Link].*;
class DistinctPrimeDigit {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);¥
[Link]("Enter a positive integer: ");
int num = [Link]();¥
if (num <= 0) {
[Link]("INVALID INPUT");
return;

boolean seen2 = false, seen3 = false, seen5 = false, seen7 = false;¥
int n = num;¥
while (n > 0) {
int d = n % 10;¥
if (d != 2 && d != 3 && d != 5 && d != 7) {
[Link]("NOT A DISTINCT PRIME DIGIT INTEGER");
return;

if (d == 2 && seen2) { [Link]("NOT A DISTINCT PRIME DIGIT INTEGER"); return; }
if (d == 3 && seen3) { [Link]("NOT A DISTINCT PRIME DIGIT INTEGER"); return; }
if (d == 5 && seen5) { [Link]("NOT A DISTINCT PRIME DIGIT INTEGER"); return; }
if (d == 7 && seen7) { [Link]("NOT A DISTINCT PRIME DIGIT INTEGER"); return; }¥
if (d == 2) seen2 = true;
if (d == 3) seen3 = true;
if (d == 5) seen5 = true;
if (d == 7) seen7 = true;¥
n = n / 10;

[Link]("IT IS A DISTINCT PRIME DIGIT INTEGER");
}
}

You might also like