×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Implement The Use if Arrays and Characters in Java Assignment Solution

July 15, 2024
Aaron O'Donnell
Aaron O'Donnell
🇬🇧 United Kingdom
Java
Aaron O'Donnell, with a Ph.D. from the University of Bristol, United Kingdom, brings 18 years of experience as an Eclipse assignment expert.
Key Topics
  • Instructions
  • Requirements and Specifications
Tip of the day
Use Python libraries effectively by importing only what you need. For example, if you're working with data, using libraries like pandas and numpy can save time and simplify complex tasks like data manipulation and analysis.
News
In 2024, the Biden-Harris Administration has expanded high-dosage tutoring and extended learning programs to boost academic achievement, helping programming students and others recover from pandemic-related setbacks. These initiatives are funded by federal resources aimed at improving math and literacy skills​

Instructions

Objective

Write a JAVA assignment program to implement arrays to solve problems.

Requirements and Specifications

Program to implement arrays in java

Source Code

#include using namespace std; bool check(int v) { return (-20 <= v) && (v <= 50); } void read15Ints(int* arr, int n) { int counter = 0; int val; while(counter < n) { cin >> val; if (check(val)) { arr[counter] = val; counter++; } else { cout << "Input value is out of bounds" << endl; } } } void showAllBySign(int* arr, int n, bool negative) { cout << (negative ? "Negatives:" : "Non-negatives:"); for (int i = 0; i if (arr[i] < 0 && negative || arr[i] >= 0 && !negative) { cout << " " << arr[i]; } } cout << endl; } void showPositiveSum(int* arr, int n) { cout << "Positive sum:"; int sum = 0; for (int i = 0; i if (arr[i] > 0) { sum += arr[i]; } } cout << sum << endl; } void showArray(int* arr, int n) { cout << "Array:"; for (int i = 0; i cout << " " << arr[i]; } cout << endl; } int main() { int arr[15], n = 15; bool isOver = false; read15Ints(arr, n); while (!isOver) { int choice = 0; cout << "Menu:" << endl; cout << "1. Show all negatives" << endl; cout << "2. Show all non-negatives" << endl; cout << "3. Show positive sum" << endl; cout << "4. Show original array" << endl; cout << "5. Exit" << endl; cout << "Your choice: "; cin >> choice; switch(choice) { case 1: showAllBySign(arr, n, true); break; case 2: showAllBySign(arr, n, false); break; case 3: showPositiveSum(arr, n); break; case 4: showArray(arr, n); break; case 5: isOver = true; break; default: cout << "Invalid input" << endl; break; } cout << endl; } cout << "Good Bye" << endl; }

Related Samples

Explore our Java programming homework samples to see how we tackle complex concepts with clarity and precision. Our curated examples showcase our expertise in Java programming, offering insights into problem-solving, code optimization, and more. Whether you're studying arrays, inheritance, or GUIs, these samples demonstrate our commitment to delivering high-quality solutions tailored to your academic needs.