This document provides an overview of arrays in Java, including how to declare, initialize, access, and modify array elements. Key points covered include: declaring arrays using type[] name = new type[size]; accessing elements using name[index]; that arrays are objects that store elements of the same type; and that the length property returns the number of elements in the array. Methods for the Arrays utility class are also described, such as toString to print an array. The document gives an example of using an array to solve a problem of tracking daily temperature values.
This document provides an overview of arrays in Java, including how to declare, initialize, access, and manipulate array elements. It discusses key array concepts like indexes, the length field, and for loops for traversing arrays. Examples are provided for common array operations like initialization, accessing elements, and passing arrays as parameters or returning them from methods. Limitations of arrays are also covered.
The document discusses arrays in Java. It begins by defining what an array is - a structured data type that stores a fixed number of elements of the same type. It then covers how to declare and initialize one-dimensional arrays, manipulate array elements using loops and indexes, and how to pass arrays as parameters to methods. The document also discusses arrays of objects and multidimensional arrays.
An array is a container that holds a fixed number of values of the same type. Arrays in Java are created in three steps: 1) declare the array name and type, 2) create the array using new, and 3) initialize the array values. The length of an array is fixed at creation. Arrays can be one-dimensional, containing a list of values, or multi-dimensional, containing other arrays. Elements in arrays are accessed via an index with the first element at index 0.
This document discusses arrays and pointers in C++. It begins by explaining that arrays allow storing multiple values of the same type, and that arrays have a fixed size and type after declaration. It then covers how to declare, initialize, access elements of, and iterate through arrays using indexes and loops. Multidimensional arrays are also explained, including how they can be thought of as tables with rows and columns. The document concludes by introducing pointers as variables that store the memory addresses of other variables.
An Introduction to Programming in Java: ArraysMartin Chapman
An Introduction to Programming in Java: Arrays. Last delivered in 2012. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
The document discusses arrays in Java. It begins by defining an array as a data structure that holds a collection of the same type of data. It then covers topics such as declaring and creating arrays, accessing array elements using indexes, default values, passing arrays to methods, returning arrays from methods, and two-dimensional arrays. Examples are provided throughout to illustrate key concepts related to working with arrays in Java programs.
The document provides information about arrays and pointers in C++. It discusses how to declare, initialize, access elements of arrays including multi-dimensional arrays. It also covers pointers, how they store memory addresses rather than values, and how to declare and assign addresses to pointers. Key topics include declaring arrays with syntax like dataType arrayName[size]; initializing arrays; accessing elements using indices; multi-dimensional arrays of different sizes; declaring pointers with syntax like int* pointer; and assigning addresses to pointers using &operator.
Arrays allow storing and accessing multiple values under a single variable name. They are indexed collections that can hold values of built-in or user-defined types. Multidimensional arrays can model matrices by using multiple indices to access elements. Parameter arrays allow methods to accept a variable number of arguments by specifying the last parameter as a type followed by ellipses.
This document provides an overview of arrays in Java, including how to declare, initialize, access, and manipulate array elements. It discusses key array concepts like indexes, the length field, and for loops for traversing arrays. Examples are provided for common array operations like initialization, accessing elements, and passing arrays as parameters or returning them from methods. Limitations of arrays are also covered.
The document discusses arrays in Java. It begins by defining what an array is - a structured data type that stores a fixed number of elements of the same type. It then covers how to declare and initialize one-dimensional arrays, manipulate array elements using loops and indexes, and how to pass arrays as parameters to methods. The document also discusses arrays of objects and multidimensional arrays.
An array is a container that holds a fixed number of values of the same type. Arrays in Java are created in three steps: 1) declare the array name and type, 2) create the array using new, and 3) initialize the array values. The length of an array is fixed at creation. Arrays can be one-dimensional, containing a list of values, or multi-dimensional, containing other arrays. Elements in arrays are accessed via an index with the first element at index 0.
This document discusses arrays and pointers in C++. It begins by explaining that arrays allow storing multiple values of the same type, and that arrays have a fixed size and type after declaration. It then covers how to declare, initialize, access elements of, and iterate through arrays using indexes and loops. Multidimensional arrays are also explained, including how they can be thought of as tables with rows and columns. The document concludes by introducing pointers as variables that store the memory addresses of other variables.
An Introduction to Programming in Java: ArraysMartin Chapman
An Introduction to Programming in Java: Arrays. Last delivered in 2012. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
The document discusses arrays in Java. It begins by defining an array as a data structure that holds a collection of the same type of data. It then covers topics such as declaring and creating arrays, accessing array elements using indexes, default values, passing arrays to methods, returning arrays from methods, and two-dimensional arrays. Examples are provided throughout to illustrate key concepts related to working with arrays in Java programs.
The document provides information about arrays and pointers in C++. It discusses how to declare, initialize, access elements of arrays including multi-dimensional arrays. It also covers pointers, how they store memory addresses rather than values, and how to declare and assign addresses to pointers. Key topics include declaring arrays with syntax like dataType arrayName[size]; initializing arrays; accessing elements using indices; multi-dimensional arrays of different sizes; declaring pointers with syntax like int* pointer; and assigning addresses to pointers using &operator.
Arrays allow storing and accessing multiple values under a single variable name. They are indexed collections that can hold values of built-in or user-defined types. Multidimensional arrays can model matrices by using multiple indices to access elements. Parameter arrays allow methods to accept a variable number of arguments by specifying the last parameter as a type followed by ellipses.
The document discusses arrays in Java, including how to declare and initialize one-dimensional and two-dimensional arrays, access array elements, pass arrays as parameters, and sort and search arrays. It also covers arrays of objects and examples of using arrays to store student data and daily temperature readings from multiple cities over multiple days.
1) Arrays allow storing and accessing multiple values of the same data type. They are declared with the data type, followed by square brackets and the array name.
2) Array components are accessed using their index number within square brackets after the array name. Index numbers start at 0.
3) The length property returns the number of components in the array, which must be considered to avoid accessing components outside the bounds of the array.
This document discusses arrays, type conversion, and the Math class in Java. It defines arrays as fixed-size collections that store elements of the same type. It shows different ways to declare and initialize arrays and provides examples of using arrays to store input from the user. The document also explains type conversion in Java using casting. Finally, it outlines commonly used methods in the Math class for numeric and mathematical operations like min, max, sqrt, and generating random numbers. Exercises are provided to practice these concepts.
This document discusses Java data types, variables, and methods. It covers primitive data types like int, float, and boolean. It describes rules for identifiers and conventions for naming variables and classes. The document defines parameter types, implicit and explicit parameters, and how to call methods. It explains constructing objects with the new operator and accessor and mutator methods. The summary concludes with a discussion of static methods and how to call them without an object.
1. The document discusses arrays, including declaring and initializing arrays, passing arrays to functions, and sorting and analyzing array data.
2. Common array operations like finding the mean, median, and mode are demonstrated using arrays of survey response data.
3. Key array concepts covered are declaring arrays with a specified size and type, accessing elements with subscripts, passing entire arrays or individual elements to functions by reference or value, and sorting an array using a bubble sort algorithm.
The document discusses arrays and string operations in C programming. It defines arrays as structures that hold related data items of the same type. It covers one-dimensional and two-dimensional arrays, including declaring, initializing, accessing, and manipulating array elements. It also defines strings as sequences of characters stored as character arrays terminated with a null character. It discusses string declaration, input/output, and standard library functions for determining string length and manipulating strings.
This document discusses arrays and multidimensional arrays in Python. It begins with an introduction to arrays, including how they allow multiple values to be stored and accessed using indices. Examples are given of one-dimensional arrays storing student IDs and quiz scores. The document then covers multidimensional arrays, providing an example of a 2D array to store temperature readings across multiple days. It describes how values in 2D arrays can be accessed using row and column indices. The remainder of the document discusses implementing arrays in functions, matrices operations using NumPy, and exercises for students to practice arrays.
This document discusses arrays in Java. It defines an array as a collection of variables of the same type referred to by a common name. Arrays can be one-dimensional or multi-dimensional. Elements in an array are accessed using an index. The document provides examples of declaring, initializing, accessing, and manipulating one-dimensional and two-dimensional arrays in Java. It also discusses passing arrays as arguments and returning arrays from methods.
This document provides information about an intro to Java programming course including loops, arrays, and good programming style. It discusses calculating employee pay using loops and conditional logic. It also covers frequent programming issues like invalid method signatures and variable scopes. The document then explains loops, arrays, and combining them. It provides examples of using while, for, and nested loops. It also demonstrates declaring, initializing, and accessing array elements as well as looping through arrays. Finally, it discusses programming style guidelines and provides an assignment on analyzing marathon race results.
In this chapter we will learn about arrays as a way to work with sequences of elements of the same type. We will explain what arrays are, how we declare, create, instantiate and use them. We will examine one-dimensional and multidimensional arrays. We will learn different ways to iterate through the array, read from the standard input and write to the standard output. We will give many example exercises, which can be solved using arrays and we will show how useful they really are.
This document provides information about loops, arrays, and good programming style from a course on introductory Java programming. It discusses the following key points:
1. Loops like while and for can be used to repeat blocks of code. Common loop issues like infinite loops and off-by-one errors are addressed.
2. Arrays provide a way to store and access multiple values of the same type. Arrays have a length property and values can be accessed using indexes.
3. Good programming style makes code more readable through use of indentation, whitespace, and meaningful names. Duplicated checks should be avoided.
The document concludes with an assignment to find the best and second best performers from
This document provides information on arrays in Java. It begins by defining an array as a collection of similar data types that can store values of a homogeneous type. Arrays must specify their size at declaration and use zero-based indexing. The document then discusses single dimensional arrays, how to declare and initialize them, and how to set and access array elements. It also covers multi-dimensional arrays, providing syntax for declaration and initialization. Examples are given for creating, initializing, accessing, and printing array elements. The document concludes with examples of searching arrays and performing operations on two-dimensional arrays like matrix addition and multiplication.
The document contains lecture notes on one-dimensional and two-dimensional arrays in C programming. It discusses the syntax, declaration, initialization, and accessing of array elements. Examples are provided to demonstrate reading input from users, traversing arrays using for loops, and performing operations like addition and multiplication on two-dimensional arrays. Class exercises described include programs to read and display arrays, find the highest number in an array, and perform matrix addition and multiplication using two-dimensional arrays.
This document contains summaries of solutions to various LeetCode problems in Java. It begins with a 3-sentence summary of the Rotate Array problem and its solutions, followed by shorter 1-sentence summaries of other problems and their solutions, including Evaluate Reverse Polish Notation, Longest Palindromic Substring, Word Break, and more. Dynamic programming and recursion are discussed as approaches for some of the problems.
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
Getting Started
Create a class called Lab8. Use the same setup for setting up your class and main method as you
did for the previous assignments. Be sure to name your file Lab8.java. Additionally, make
another file called Arrays.java. This file will be an object, so simply start it off by declaring an
Arrays class. You can copy the following skeleton and fill in the appropriate code below each of
the comments:
public class Arrays {
/ Instance Variables
// Constructors
// findMin 1
// findMax
// calcSum
// calcAverage
// toString
}
Task Overview
Your task for this lab is to create a class called Arrays with some array processing methods. This
class will maintain an array and the number of elements present in it. Additionally, methods will
be available to display the current min and max elements along with the average of all of them.
Finally, a toString() method will be available to cleanly display all the array elements. Finally,
you will write a simple driver class to test out the above Arrays class.
Part 1: Instance Variables for Arrays
The first thing to do for the Arrays class is to set up its instance variables. Declare the following
(private) instance variables:
• An int array called array ? this will be the array we will be writing methods for.
• An int called count - this represents the number of valid elements in the array.
Part 2:
Constructors for Arrays The Arrays class will have two constructors. The first constructor takes
the maximum size of the array as input as a parameter and initializes the array instance variable
appropriately. It also sets count to size. Finally, it will initialize all of the array elements to some
values between 0 and 10, inclusive. To create this constructor, follow these steps:
• Import java.util.Random to make use of the random number generator.
• Create a constructor with the following header: public Arrays(int size)
• Initialize your array variable and set its size to size (see the chart on page 252 for reference on
initializing arrays). Be very careful that you are setting the value of your array instance variable,
as opposed to creating a new variable called array.
• Set the value of the count variable to size because we will be populating the entire array.
• Copy the following code to the constructor in order to generate random values between 0 and
10, inclusive:
Random rand = new Random();
for (int i = 0; i < count; i++)
{
array[i] = (rand.nextInt(10));
}
Next, create another constructor with the following header: public Arrays(int[] arr). This
constructor will initialize the class by using the passed arr argument in order to fill its instance
variables. The following things need to be done inside of this constructor:
• Set the array variable equal to arr.
• Set the count variable equal to the length of the array.
Part 3: Displaying the Output findMin()
The first method of this class will search the array for the minimum element. Copy the following
code for the findMin method. Note how the count i.
Arrays allow storing multiple values of the same type in a single variable. An array is declared by specifying the data type, followed by square brackets containing the array name. Individual elements in the array are accessed using their index number within square brackets after the array name. The Arrays class contains methods for sorting, searching, comparing, and filling arrays that are overloaded for all primitive data types.
This document discusses arrays in Java. It covers concepts like array rotation, inserting values into sorted arrays while maintaining sort order, using arrays with String and Graphics methods, initializing and using arrays of objects, avoiding null pointer exceptions, passing command line arguments as arrays, and using the Arrays utility class methods like binarySearch, sort, and toString. Examples are provided to demonstrate array rotation, searching/sorting numbers, and parsing command line arguments.
This document discusses arrays in C programming. It begins with an introduction to arrays as structures for storing related data items of the same type. It then covers key topics like declaring and initializing arrays, passing arrays to functions, and sorting and searching arrays. Examples are provided to demonstrate array concepts like initializing character arrays for strings, passing an entire array versus individual elements to functions, and using arrays to calculate the mean, median, and mode of a data set. Functions are defined to implement sorting, searching, and calculating statistical values on arrays.
Programming in Java: Arrays. Last delivered in 2016. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
Boost Your Savings with These Money Management AppsJhone kinadey
A money management app can transform your financial life by tracking expenses, creating budgets, and setting financial goals. These apps offer features like real-time expense tracking, bill reminders, and personalized insights to help you save and manage money effectively. With a user-friendly interface, they simplify financial planning, making it easier to stay on top of your finances and achieve long-term financial stability.
The document discusses arrays in Java, including how to declare and initialize one-dimensional and two-dimensional arrays, access array elements, pass arrays as parameters, and sort and search arrays. It also covers arrays of objects and examples of using arrays to store student data and daily temperature readings from multiple cities over multiple days.
1) Arrays allow storing and accessing multiple values of the same data type. They are declared with the data type, followed by square brackets and the array name.
2) Array components are accessed using their index number within square brackets after the array name. Index numbers start at 0.
3) The length property returns the number of components in the array, which must be considered to avoid accessing components outside the bounds of the array.
This document discusses arrays, type conversion, and the Math class in Java. It defines arrays as fixed-size collections that store elements of the same type. It shows different ways to declare and initialize arrays and provides examples of using arrays to store input from the user. The document also explains type conversion in Java using casting. Finally, it outlines commonly used methods in the Math class for numeric and mathematical operations like min, max, sqrt, and generating random numbers. Exercises are provided to practice these concepts.
This document discusses Java data types, variables, and methods. It covers primitive data types like int, float, and boolean. It describes rules for identifiers and conventions for naming variables and classes. The document defines parameter types, implicit and explicit parameters, and how to call methods. It explains constructing objects with the new operator and accessor and mutator methods. The summary concludes with a discussion of static methods and how to call them without an object.
1. The document discusses arrays, including declaring and initializing arrays, passing arrays to functions, and sorting and analyzing array data.
2. Common array operations like finding the mean, median, and mode are demonstrated using arrays of survey response data.
3. Key array concepts covered are declaring arrays with a specified size and type, accessing elements with subscripts, passing entire arrays or individual elements to functions by reference or value, and sorting an array using a bubble sort algorithm.
The document discusses arrays and string operations in C programming. It defines arrays as structures that hold related data items of the same type. It covers one-dimensional and two-dimensional arrays, including declaring, initializing, accessing, and manipulating array elements. It also defines strings as sequences of characters stored as character arrays terminated with a null character. It discusses string declaration, input/output, and standard library functions for determining string length and manipulating strings.
This document discusses arrays and multidimensional arrays in Python. It begins with an introduction to arrays, including how they allow multiple values to be stored and accessed using indices. Examples are given of one-dimensional arrays storing student IDs and quiz scores. The document then covers multidimensional arrays, providing an example of a 2D array to store temperature readings across multiple days. It describes how values in 2D arrays can be accessed using row and column indices. The remainder of the document discusses implementing arrays in functions, matrices operations using NumPy, and exercises for students to practice arrays.
This document discusses arrays in Java. It defines an array as a collection of variables of the same type referred to by a common name. Arrays can be one-dimensional or multi-dimensional. Elements in an array are accessed using an index. The document provides examples of declaring, initializing, accessing, and manipulating one-dimensional and two-dimensional arrays in Java. It also discusses passing arrays as arguments and returning arrays from methods.
This document provides information about an intro to Java programming course including loops, arrays, and good programming style. It discusses calculating employee pay using loops and conditional logic. It also covers frequent programming issues like invalid method signatures and variable scopes. The document then explains loops, arrays, and combining them. It provides examples of using while, for, and nested loops. It also demonstrates declaring, initializing, and accessing array elements as well as looping through arrays. Finally, it discusses programming style guidelines and provides an assignment on analyzing marathon race results.
In this chapter we will learn about arrays as a way to work with sequences of elements of the same type. We will explain what arrays are, how we declare, create, instantiate and use them. We will examine one-dimensional and multidimensional arrays. We will learn different ways to iterate through the array, read from the standard input and write to the standard output. We will give many example exercises, which can be solved using arrays and we will show how useful they really are.
This document provides information about loops, arrays, and good programming style from a course on introductory Java programming. It discusses the following key points:
1. Loops like while and for can be used to repeat blocks of code. Common loop issues like infinite loops and off-by-one errors are addressed.
2. Arrays provide a way to store and access multiple values of the same type. Arrays have a length property and values can be accessed using indexes.
3. Good programming style makes code more readable through use of indentation, whitespace, and meaningful names. Duplicated checks should be avoided.
The document concludes with an assignment to find the best and second best performers from
This document provides information on arrays in Java. It begins by defining an array as a collection of similar data types that can store values of a homogeneous type. Arrays must specify their size at declaration and use zero-based indexing. The document then discusses single dimensional arrays, how to declare and initialize them, and how to set and access array elements. It also covers multi-dimensional arrays, providing syntax for declaration and initialization. Examples are given for creating, initializing, accessing, and printing array elements. The document concludes with examples of searching arrays and performing operations on two-dimensional arrays like matrix addition and multiplication.
The document contains lecture notes on one-dimensional and two-dimensional arrays in C programming. It discusses the syntax, declaration, initialization, and accessing of array elements. Examples are provided to demonstrate reading input from users, traversing arrays using for loops, and performing operations like addition and multiplication on two-dimensional arrays. Class exercises described include programs to read and display arrays, find the highest number in an array, and perform matrix addition and multiplication using two-dimensional arrays.
This document contains summaries of solutions to various LeetCode problems in Java. It begins with a 3-sentence summary of the Rotate Array problem and its solutions, followed by shorter 1-sentence summaries of other problems and their solutions, including Evaluate Reverse Polish Notation, Longest Palindromic Substring, Word Break, and more. Dynamic programming and recursion are discussed as approaches for some of the problems.
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
Getting Started
Create a class called Lab8. Use the same setup for setting up your class and main method as you
did for the previous assignments. Be sure to name your file Lab8.java. Additionally, make
another file called Arrays.java. This file will be an object, so simply start it off by declaring an
Arrays class. You can copy the following skeleton and fill in the appropriate code below each of
the comments:
public class Arrays {
/ Instance Variables
// Constructors
// findMin 1
// findMax
// calcSum
// calcAverage
// toString
}
Task Overview
Your task for this lab is to create a class called Arrays with some array processing methods. This
class will maintain an array and the number of elements present in it. Additionally, methods will
be available to display the current min and max elements along with the average of all of them.
Finally, a toString() method will be available to cleanly display all the array elements. Finally,
you will write a simple driver class to test out the above Arrays class.
Part 1: Instance Variables for Arrays
The first thing to do for the Arrays class is to set up its instance variables. Declare the following
(private) instance variables:
• An int array called array ? this will be the array we will be writing methods for.
• An int called count - this represents the number of valid elements in the array.
Part 2:
Constructors for Arrays The Arrays class will have two constructors. The first constructor takes
the maximum size of the array as input as a parameter and initializes the array instance variable
appropriately. It also sets count to size. Finally, it will initialize all of the array elements to some
values between 0 and 10, inclusive. To create this constructor, follow these steps:
• Import java.util.Random to make use of the random number generator.
• Create a constructor with the following header: public Arrays(int size)
• Initialize your array variable and set its size to size (see the chart on page 252 for reference on
initializing arrays). Be very careful that you are setting the value of your array instance variable,
as opposed to creating a new variable called array.
• Set the value of the count variable to size because we will be populating the entire array.
• Copy the following code to the constructor in order to generate random values between 0 and
10, inclusive:
Random rand = new Random();
for (int i = 0; i < count; i++)
{
array[i] = (rand.nextInt(10));
}
Next, create another constructor with the following header: public Arrays(int[] arr). This
constructor will initialize the class by using the passed arr argument in order to fill its instance
variables. The following things need to be done inside of this constructor:
• Set the array variable equal to arr.
• Set the count variable equal to the length of the array.
Part 3: Displaying the Output findMin()
The first method of this class will search the array for the minimum element. Copy the following
code for the findMin method. Note how the count i.
Arrays allow storing multiple values of the same type in a single variable. An array is declared by specifying the data type, followed by square brackets containing the array name. Individual elements in the array are accessed using their index number within square brackets after the array name. The Arrays class contains methods for sorting, searching, comparing, and filling arrays that are overloaded for all primitive data types.
This document discusses arrays in Java. It covers concepts like array rotation, inserting values into sorted arrays while maintaining sort order, using arrays with String and Graphics methods, initializing and using arrays of objects, avoiding null pointer exceptions, passing command line arguments as arrays, and using the Arrays utility class methods like binarySearch, sort, and toString. Examples are provided to demonstrate array rotation, searching/sorting numbers, and parsing command line arguments.
This document discusses arrays in C programming. It begins with an introduction to arrays as structures for storing related data items of the same type. It then covers key topics like declaring and initializing arrays, passing arrays to functions, and sorting and searching arrays. Examples are provided to demonstrate array concepts like initializing character arrays for strings, passing an entire array versus individual elements to functions, and using arrays to calculate the mean, median, and mode of a data set. Functions are defined to implement sorting, searching, and calculating statistical values on arrays.
Programming in Java: Arrays. Last delivered in 2016. All educational material listed or linked to on these pages in relation to King's College London may be provided for reference only, and therefore does not necessarily reflect the current course content.
Boost Your Savings with These Money Management AppsJhone kinadey
A money management app can transform your financial life by tracking expenses, creating budgets, and setting financial goals. These apps offer features like real-time expense tracking, bill reminders, and personalized insights to help you save and manage money effectively. With a user-friendly interface, they simplify financial planning, making it easier to stay on top of your finances and achieve long-term financial stability.
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...kalichargn70th171
Visual testing plays a vital role in ensuring that software products meet the aesthetic requirements specified by clients in functional and non-functional specifications. In today's highly competitive digital landscape, users expect a seamless and visually appealing online experience. Visual testing, also known as automated UI testing or visual regression testing, verifies the accuracy of the visual elements that users interact with.
The Comprehensive Guide to Validating Audio-Visual Performances.pdfkalichargn70th171
Ensuring the optimal performance of your audio-visual (AV) equipment is crucial for delivering exceptional experiences. AV performance validation is a critical process that verifies the quality and functionality of your AV setup. Whether you're a content creator, a business conducting webinars, or a homeowner creating a home theater, validating your AV performance is essential.
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid
IBM watsonx Code Assistant for Z, our latest Generative AI-assisted mainframe application modernization solution. Mainframe (IBM Z) application modernization is a topic that every mainframe client is addressing to various degrees today, driven largely from digital transformation. With generative AI comes the opportunity to reimagine the mainframe application modernization experience. Infusing generative AI will enable speed and trust, help de-risk, and lower total costs associated with heavy-lifting application modernization initiatives. This document provides an overview of the IBM watsonx Code Assistant for Z which uses the power of generative AI to make it easier for developers to selectively modernize COBOL business services while maintaining mainframe qualities of service.
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio, Inc.
Alluxio Webinar
June. 18, 2024
For more Alluxio Events: https://www.alluxio.io/events/
Speaker:
- Jianjian Xie (Staff Software Engineer, Alluxio)
As Trino users increasingly rely on cloud object storage for retrieving data, speed and cloud cost have become major challenges. The separation of compute and storage creates latency challenges when querying datasets; scanning data between storage and compute tiers becomes I/O bound. On the other hand, cloud API costs related to GET/LIST operations and cross-region data transfer add up quickly.
The newly introduced Trino file system cache by Alluxio aims to overcome the above challenges. In this session, Jianjian will dive into Trino data caching strategies, the latest test results, and discuss the multi-level caching architecture. This architecture makes Trino 10x faster for data lakes of any scale, from GB to EB.
What you will learn:
- Challenges relating to the speed and costs of running Trino in the cloud
- The new Trino file system cache feature overview, including the latest development status and test results
- A multi-level cache framework for maximized speed, including Trino file system cache and Alluxio distributed cache
- Real-world cases, including a large online payment firm and a top ridesharing company
- The future roadmap of Trino file system cache and Trino-Alluxio integration
Consistent toolbox talks are critical for maintaining workplace safety, as they provide regular opportunities to address specific hazards and reinforce safe practices.
These brief, focused sessions ensure that safety is a continual conversation rather than a one-time event, which helps keep safety protocols fresh in employees' minds. Studies have shown that shorter, more frequent training sessions are more effective for retention and behavior change compared to longer, infrequent sessions.
Engaging workers regularly, toolbox talks promote a culture of safety, empower employees to voice concerns, and ultimately reduce the likelihood of accidents and injuries on site.
The traditional method of conducting safety talks with paper documents and lengthy meetings is not only time-consuming but also less effective. Manual tracking of attendance and compliance is prone to errors and inconsistencies, leading to gaps in safety communication and potential non-compliance with OSHA regulations. Switching to a digital solution like Safelyio offers significant advantages.
Safelyio automates the delivery and documentation of safety talks, ensuring consistency and accessibility. The microlearning approach breaks down complex safety protocols into manageable, bite-sized pieces, making it easier for employees to absorb and retain information.
This method minimizes disruptions to work schedules, eliminates the hassle of paperwork, and ensures that all safety communications are tracked and recorded accurately. Ultimately, using a digital platform like Safelyio enhances engagement, compliance, and overall safety performance on site. https://safelyio.com/
Mobile App Development Company In Noida | Drona InfotechDrona Infotech
React.js, a JavaScript library developed by Facebook, has gained immense popularity for building user interfaces, especially for single-page applications. Over the years, React has evolved and expanded its capabilities, becoming a preferred choice for mobile app development. This article will explore why React.js is an excellent choice for the Best Mobile App development company in Noida.
Visit Us For Information: https://www.linkedin.com/pulse/what-makes-reactjs-stand-out-mobile-app-development-rajesh-rai-pihvf/
Penify - Let AI do the Documentation, you write the Code.KrishnaveniMohan1
Penify automates the software documentation process for Git repositories. Every time a code modification is merged into "main", Penify uses a Large Language Model to generate documentation for the updated code. This automation covers multiple documentation layers, including InCode Documentation, API Documentation, Architectural Documentation, and PR documentation, each designed to improve different aspects of the development process. By taking over the entire documentation process, Penify tackles the common problem of documentation becoming outdated as the code evolves.
https://www.penify.dev/
Superpower Your Apache Kafka Applications Development with Complementary Open...Paul Brebner
Kafka Summit talk (Bangalore, India, May 2, 2024, https://events.bizzabo.com/573863/agenda/session/1300469 )
Many Apache Kafka use cases take advantage of Kafka’s ability to integrate multiple heterogeneous systems for stream processing and real-time machine learning scenarios. But Kafka also exists in a rich ecosystem of related but complementary stream processing technologies and tools, particularly from the open-source community. In this talk, we’ll take you on a tour of a selection of complementary tools that can make Kafka even more powerful. We’ll focus on tools for stream processing and querying, streaming machine learning, stream visibility and observation, stream meta-data, stream visualisation, stream development including testing and the use of Generative AI and LLMs, and stream performance and scalability. By the end you will have a good idea of the types of Kafka “superhero” tools that exist, which are my favourites (and what superpowers they have), and how they combine to save your Kafka applications development universe from swamploads of data stagnation monsters!
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...kalichargn70th171
In today's fiercely competitive mobile app market, the role of the QA team is pivotal for continuous improvement and sustained success. Effective testing strategies are essential to navigate the challenges confidently and precisely. Ensuring the perfection of mobile apps before they reach end-users requires thoughtful decisions in the testing plan.
Enhanced Screen Flows UI/UX using SLDS with Tom KittPeter Caitens
Join us for an engaging session led by Flow Champion, Tom Kitt. This session will dive into a technique of enhancing the user interfaces and user experiences within Screen Flows using the Salesforce Lightning Design System (SLDS). This technique uses Native functionality, with No Apex Code, No Custom Components and No Managed Packages required.
WWDC 2024 Keynote Review: For CocoaCoders AustinPatrick Weigel
Overview of WWDC 2024 Keynote Address.
Covers: Apple Intelligence, iOS18, macOS Sequoia, iPadOS, watchOS, visionOS, and Apple TV+.
Understandable dialogue on Apple TV+
On-device app controlling AI.
Access to ChatGPT with a guest appearance by Chief Data Thief Sam Altman!
App Locking! iPhone Mirroring! And a Calculator!!
The Role of DevOps in Digital Transformation.pdfmohitd6
DevOps plays a crucial role in driving digital transformation by fostering a collaborative culture between development and operations teams. This approach enhances the speed and efficiency of software delivery, ensuring quicker deployment of new features and updates. DevOps practices like continuous integration and continuous delivery (CI/CD) streamline workflows, reduce manual errors, and increase the overall reliability of software systems. By leveraging automation and monitoring tools, organizations can improve system stability, enhance customer experiences, and maintain a competitive edge. Ultimately, DevOps is pivotal in enabling businesses to innovate rapidly, respond to market changes, and achieve their digital transformation goals.
2. Can we solve this problem?
• Consider the following program (input underlined):
How many days' temperatures? 7
Day 1's high temp: 45
Day 2's high temp: 44
Day 3's high temp: 39
Day 4's high temp: 48
Day 5's high temp: 37
Day 6's high temp: 46
Day 7's high temp: 53
Average temp = 44.6
4 days were above average.
3. Why the problem is hard
• We need each input value twice
oto compute the average (a cumulative sum)
oto count how many were above average
• We could read each value into a variable... but we
odon't know how many days are needed until the program runs
odon't know how many variables to declare
• We need a way to declare many variables in one step.
4. Arrays
• array: object that stores many values of the same type.
oelement: One value in an array.
oindex: A 0-based integer to access an element from an array.
index 0 1 2 3 4 5 6 7 8 9
value 12 49 -2 26 5 17 -6 84 72 3
element 0 element 4 element 9
5. Array declaration
Type[] name = new Type[integer-expr];
Example: int[] numbers = new int[10];
index 0 1 2 3 4 5 6 7 8 9
value 0 0 0 0 0 0 0 0 0 0
6. Array declaration, cont.
• The length can be any
integer expression.
int x = 2 * 3 + 1;
int[] data;
data = new int[x % 5 + 2];
• Each element initially gets a
"zero-equivalent" value.
Type Default Value
int 0
double 0.0
boolean false
String
(or other object)
null
(no object)
8. Arrays of other types
double[] results = new double[5];
results[2] = 3.4;
results[4] = -0.5;
boolean[] tests = new boolean[6];
tests[3] = true;
index 0 1 2 3 4
value 0.0 0.0 3.4 0.0 -0.5
index 0 1 2 3 4 5
value false false false true false false
9. Out-of-bounds
• Legal indexes: between 0 and the length of the array - 1.
oInterval notation: [0, arrayName.length)
oReading or writing any index outside this range will throw an
ArrayIndexOutOfBoundsException.
Example:
int[] data = new int[6]
System.out.println(data[0]);
System.out.println(data[5]);
System.out.println(data[-1]);
System.out.println(data[6]);
index 0 1 2 3 4 5
value 0 0 0 0 0 0
10. Accessing array elements
int[] numbers = new int[8];
numbers[1] = 3;
numbers[4] = 99;
numbers[6] = 2;
int x = numbers[1];
numbers[x] = 42;
numbers[numbers[6]] = 11;
x
numbers
x 3
index 0 1 2 3 4 5 6 7
value
index 0 1 2 3 4 5 6 7
value 0 3 11 42 99 0 2 0
11. Arrays and for loops
• It is common to use for loops to access array elements.
for (int i = 0; i < 8; i++) {
System.out.print(numbers[i] + " ");
}
System.out.println();
• Sometimes we assign each element a value in a loop.
for (int i = 0; i < 8; i++) {
numbers[i] = ?
}
index 0 1 2 3 4 5 6 7
value 0 2 4 6 8 10 12 14
12. The length field
• An array's length field stores its number of elements.
name.length
for (int i = 0; i < numbers.length; i++) {
System.out.print(numbers[i] + " ");
}
oIt does NOT use parentheses like a String's length() method
• What expressions refer to:
oThe last element of any array?
oThe middle element?
13. Weather question
• Use an array to solve the weather problem:
How many days' temperatures? 7
Day 1's high temp: 45
Day 2's high temp: 44
Day 3's high temp: 39
Day 4's high temp: 48
Day 5's high temp: 37
Day 6's high temp: 46
Day 7's high temp: 53
Average temp = 44.6
4 days were above average.
14. Weather answer
// Reads temperatures from the user, computes average and # days above average.
import java.util.*;
public class Weather {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.print("How many days' temperatures? ");
int days = console.nextInt();
// Create temperature array
...
int sum = 0;
for (int i = 0; i < days; i++) { // read/store each day's temperature
System.out.print("Day " + (i + 1) + "'s high temp: ");
// Store temperature in array
...
// Update sum
...
}
double average = (double) sum / days;
int count = 0;
// Count days over average
...
// Report results
System.out.printf("Average temp = %.1fn", average);
System.out.println(count + " days above average");
}
}
15. Quick array initialization
type[] name = {value, value, ... ,value};
Example:
int[] numbers = {12, 49, -2, 26, 5, 17, -6};
oUseful when you know what the array's elements will be
oThe compiler figures out the size by counting the values
index 0 1 2 3 4 5 6
value 12 49 -2 26 5 17 -6
16. "Array mystery" problem
• traversal: An examination of each element of an array.
int[] a = {1, 7, 5, 6, 4, 14, 11};
for (int i = 0; i < a.length - 1; i++) {
if (a[i] > a[i + 1]) {
a[i + 1] = a[i + 1] * 2;
}
}
index 0 1 2 3 4 5 6
value
index 0 1 2 3 4 5 6
value 1 7 10 12 8 14 22
17. Limitations of arrays
•You cannot resize an existing array:
int[] a = new int[4];
a.length = 10;
•You cannot compare arrays with == or equals:
int[] a1 = {42, -7, 1, 15};
int[] a2 = {42, -7, 1, 15};
if (a1 == a2) { ... } // false!
if (a1.equals(a2)) { ... } // false!
•An array does not know how to print itself:
int[] a1 = {42, -7, 1, 15};
System.out.println(a1); // [I@98f8c4]
18. The Arrays class
• Class Arrays in package java.util has useful static methods for
manipulating arrays:
• Syntax: Arrays.methodName(parameters)
Method name Description
binarySearch(array, value) returns the index of the given value in a sorted array
(or < 0 if not found)
copyOf(array, length) returns a new copy of an array
equals(array1, array2) returns true if the two arrays contain same elements
in the same order
fill(array, value) sets every element to the given value
sort(array) arranges the elements into sorted order
toString(array) returns a string representing the array
e.g. "[10, 30, -25, 17]"
19. Arrays.toString
• Arrays.toString accepts an array as a parameter and returns
a String representation of its elements.
int[] e = {0, 2, 4, 6, 8};
e[1] = e[3] + e[4];
System.out.println("e is " + Arrays.toString(e));
Output?
e is [0, 14, 4, 6, 8]
• Must import java.util.*;
20. Weather Question Redux
• Modify the weather program to print the following output:
How many days' temperatures? 7
Day 1's high temp: 45
Day 2's high temp: 44
Day 3's high temp: 39
Day 4's high temp: 48
Day 5's high temp: 37
Day 6's high temp: 46
Day 7's high temp: 53
Average temp = 44.6
4 days were above average.
Temperatures: [45, 44, 39, 48, 37, 46, 53]
Two coldest days: 37, 39
Two hottest days: 53, 48
21. Weather Redux Answer
// Reads temperatures from the user, computes average and # days above average.
import java.util.*;
public class Weather2 {
public static void main(String[] args) {
...
// array to store days' temperatures
int[] temps = new int[days];
... (same as Weather program)
// report results
System.out.printf("Average temp = %.1fn", average);
System.out.println(count + " days above average");
// Print array
// Find 2 mins, 2 maxes
// Print mins and maxes
}
}
Method name
binarySearch(array, value)
copyOf(array, length)
equals(array1, array2)
fill(array, value)
sort(array)
toString(array)
23. Swapping Values
public static void main(String[] args) {
int a = 7;
int b = 35;
// swap a with b?
a = b;
b = a;
System.out.println(a + " " + b);
}
• What is wrong with this code? What is its output?
• How do we fix this ?
24. Array Reversal Question
• Write code that reverses the elements of an array.
oFor example, if the array initially stores:
[11, 42, -5, 27, 0, 89]
oThen after your reversal code, it should store:
[89, 0, 27, -5, 42, 11]
• The code should work for an array of any size.
• Hint: think about swapping various elements...
25. Algorithm Idea
• Swap pairs of elements from the edges; work inwards:
index 0 1 2 3 4 5
value 11 42 -5 27 0 89
index 0 1 2 3 4 5
value 89 42 -5 27 0 11
index 0 1 2 3 4 5
value 89 0 -5 27 42 11
index 0 1 2 3 4 5
value 89 0 27 -5 42 11
26. Algorithm
• Attempt to reverse
int[] numbers = [11, 42, -5, 27, 0, 89];
// reverse the array
for (int i = 0; i < numbers.length; i++) {
// Swap edge elements
}
• Oops, doesn’t work!
oHow to fix?
27. Array Reverse Question 2
• Turn your array reversal code into a reverse method.
oAccept the array of integers to reverse as a parameter.
int[] numbers = {11, 42, -5, 27, 0, 89};
reverse(numbers);
oHow do we write methods that accept arrays as parameters?
oWill we need to return the new array contents after reversal?
28. Array Parameter (Declaration)
public static return_type methodName(type[] name) {
// Returns the average of the given array of numbers.
public static double average(int[] numbers) {
// Compute average and return
}
• You don't specify the array's length (but you can examine it).
29. Array Parameter (Call)
methodName(arrayName);
Example:
public class MyProgram {
public static void main(String[] args) {
// figure out the average temperature
int[] temps = {64, 80, 55, 72, 40};
double avg = average(temps);
System.out.println("Average temp = " + avg);
}
...
oNotice that you don't write the brackets [] when passing the array.
30. Array Return (Declaration)
public static type[] methodName(parameters) {
• Example:
// Returns a new array with two copies of each value.
// Example: [1, 4, 0, 7] -> [1, 1, 4, 4, 0, 0, 7, 7]
public static int[] stutter(int[] numbers) {
int[] result = [2 * numbers.length];
...
return result;
}
33. A swap method?
• Does the following swap method work? Why or why not?
public static void main(String[] args) {
int a = 7;
int b = 35;
// swap a with b?
swap(a, b);
System.out.println(a + " " + b);
}
public static void swap(int a, int b) {
int temp = a;
a = b;
b = temp;
}
34. Value Semantics
• value semantics: Behavior where values are copied when
assigned, passed as parameters, or returned.
oAll primitive types in Java use value semantics.
oWhen one variable is assigned to another, its value is copied.
oModifying the value of one variable does not affect others.
int x = 5;
int y = x; // x = 5, y = 5
y = 17; // x = 5, y = 17
x = 8; // x = 8, y = 17
35. Reference semantics (objects)
• reference semantics: Behavior where variables actually store the
address of an object in memory.
• When one variable is assigned to another, the object is
not copied; both variables refer to the same object
• Modifying the value of one variable will affect others.
int[] a1 = {4, 15, 8};
int[] a2 = a1; // refer to same array as a1
a2[0] = 7;
System.out.println(Arrays.toString(a1)); // [7, 15, 8]
index 0 1 2
value 4 15 8
index 0 1 2
value 7 15 8
a1 a2
36. References and Objects
• Arrays and objects use reference semantics. Why?
oefficiency. Copying large objects slows down a program.
osharing. It's useful to share an object's data among methods.
DrawingPanel panel1 = new DrawingPanel(80, 50);
DrawingPanel panel2 = panel1; // same window
panel2.setBackground(Color.CYAN);
panel1
panel2
37. Objects as Parameters
• When an object is passed as a parameter, the object is not copied.
The parameter refers to the same object.
• If the parameter is modified, it will affect the original object.
public static void main(String[] args) {
DrawingPanel window = new DrawingPanel(80, 50);
window.setBackground(Color.YELLOW);
example(window);
}
public static void example(DrawingPanel panel) {
panel.setBackground(Color.CYAN);
...
}
panel
window
38. Arrays Pass by Reference
• Arrays are passed as parameters by reference.
• Changes made in the method are also seen by the caller.
public static void main(String[] args) {
int[] iq = {126, 167, 95};
getSmurt(iq);
System.out.println(Arrays.toString(iq));
}
public static void getSmurt(int[] a) {
for (int i = 0; i < a.length; i++) {
a[i] = a[i] * 2;
}
}
o Output:
[252, 334, 190]
index 0 1 2
value 126 167 95
index 0 1 2
value 252 334 190
iq
a
39. Array Reverse Question 2
• Turn your array reversal code into a reverse method.
oAccept the array of integers to reverse as a parameter.
int[] numbers = {11, 42, -5, 27, 0, 89};
reverse(numbers);
• Solution:
public static void reverse(int[] numbers) {
for (int i = 0; i < numbers.length / 2; i++) {
int temp = numbers[i];
numbers[i] = numbers[numbers.length - 1 - i];
numbers[numbers.length - 1 - i] = temp;
}
}
40. Array parameter questions
• Write a method swap that accepts an arrays of integers and two indexes
and swaps the elements at those indexes.
int[] a1 = {12, 34, 56};
swap(a1, 1, 2);
System.out.println(Arrays.toString(a1)); // [12, 56, 34]
• Write a method swapAll that accepts two arrays of integers as parameters
and swaps their entire contents. Assume that the two arrays are the same
length.
int[] a1 = {12, 34, 56};
int[] a2 = {20, 50, 80};
swapAll(a1, a2);
System.out.println(Arrays.toString(a1)); // [20, 50, 80]
System.out.println(Arrays.toString(a2)); // [12, 34, 56]
41. Array return question
• Write a method merge that accepts two arrays of integers and returns a new
array containing all elements of the first array followed by all elements of the
second.
int[] a1 = {12, 34, 56};
int[] a2 = {7, 8, 9, 10};
int[] a3 = merge(a1, a2);
System.out.println(Arrays.toString(a3));
// [12, 34, 56, 7, 8, 9, 10]
• Write a method merge3 that merges 3 arrays similarly.
int[] a1 = {12, 34, 56};
int[] a2 = {7, 8, 9, 10};
int[] a3 = {444, 222, -1};
int[] a4 = merge3(a1, a2, a3);
System.out.println(Arrays.toString(a4));
// [12, 34, 56, 7, 8, 9, 10, 444, 222, -1]
42. Array return: merge3
// Returns a new array containing all elements of a1, a2, a3.
public static int[] merge3(int[] a1, int[] a2, int[] a3) {
int[] a4 = new int[a1.length + a2.length + a3.length];
for (int i = 0; i < a1.length; i++) {
a4[i] = a1[i];
}
for (int i = 0; i < a2.length; i++) {
a4[a1.length + i] = a2[i];
}
for (int i = 0; i < a3.length; i++) {
a4[a1.length + a2.length + i] = a3[i];
}
return a4;
}
// Can we write merge3 more concisely?
44. A multi-counter problem
• Problem: Write a method mostFrequentDigit that returns the
digit value that occurs most frequently in a positive number.
• Example:
The number 669260267 contains: one 0, two 2’s, four 6’s, one 7, and one 9.
mostFrequentDigit(669260267) returns 6.
• If there is a tie, return the digit with the lower value.
mostFrequentDigit(57135203) returns 3.
45. A multi-counter problem
• We could declare 10 counter variables ...
int counter0, counter1, counter2, counter3, counter4,
counter5, counter6, counter7, counter8, counter9;
• But a better solution would be to ?
oUse an array of counts
oExample for 669260267:
oHow do we build such an array? And how does it help?
index 0 1 2 3 4 5 6 7 8 9
value 1 0 2 0 0 0 4 1 0 0
46. Tally solution
// Returns the digit value that occurs most frequently in n.
// Breaks ties by choosing the smaller value.
public static int mostFrequentDigit(int n) {
// Create array of counts
// Tally the digits
// Find most frequently occurring digit
}
47. Array histogram question
• Given a file of integer exam scores, such as:
82
66
79
63
83
Write a program that will print a histogram of stars indicating the number of
students who earned each unique exam score.
85: *****
86: ************
87: ***
88: *
91: ****
48. Array histogram answer
// Reads a file of test scores and shows a histogram of score distribution.
import java.io.*;
import java.util.*;
public class Histogram {
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File("midterm.txt"));
// Create array of counters // counters of test scores 0 - 100
while (input.hasNextInt()) { // read file into counts array
int score = input.nextInt();
// Increment appropriate counter
}
for (int i = 0; i < counts.length; i++) { // print star histogram
if (counts[i] > 0) {
System.out.print(i + ": ");
for (int j = 0; j < counts[i]; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
}
49. Section attendance question
• Read a file of section attendance (see next slide):
yynyyynayayynyyyayanyyyaynayyayyanayyyanyayna
ayyanyyyyayanaayyanayyyananayayaynyayayynynya
yyayaynyyayyanynnyyyayyanayaynannnyyayyayayny
• And produce the following output:
Section 1
Student points: [20, 17, 19, 16, 13]
Student grades: [100.0, 85.0, 95.0, 80.0, 65.0]
Section 2
Student points: [17, 20, 16, 16, 10]
Student grades: [85.0, 100.0, 80.0, 80.0, 50.0]
Section 3
Student points: [17, 18, 17, 20, 16]
Student grades: [85.0, 90.0, 85.0, 100.0, 80.0]
• Students earn 3 points for each section attended up to 20.
50. oEach line represents a section.
oA line consists of 9 weeks' worth of data.
Each week has 5 characters because there are 5 students.
oWithin each week, each character represents one student.
a means the student was absent (+0 points)
n means they attended but didn't do the problems (+2 points)
y means they attended and did the problems (+3 points)
Section input file
yynyyynayayynyyyayanyyyaynayyayyanayyyanyayna
ayyanyyyyayanaayyanayyyananayayaynyayayynynya
yyayaynyyayyanynnyyyayyanayaynannnyyayyayayny
week 1 2 3 4 5 6 7 8 9
student 123451234512345123451234512345123451234512345
section 1
section 2
section 3
51. Section attendance answer
import java.io.*;
import java.util.*;
public class Sections {
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File("sections.txt"));
int section = 1;
while (input.hasNextLine()) {
String line = input.nextLine(); // process one section
// ??: Create points array
for (int i = 0; i < line.length(); i++) {
int student = ??
int earned = 0;
if (line.charAt(i) == 'y') { // c == 'y' or 'n' or 'a'
earned = 3;
} else if (line.charAt(i) == 'n') {
earned = 2;
}
points[student] = ??(20, points[student] + earned);
}
53. Data transformations
• In many problems we transform data between forms.
oExample: count of each digit in a number, most frequent digit
oOften each transformation is computed/stored as an array.
oFor structure, a transformation is often put in its own method.
54. Data transformations
• Sometimes we map between data and array indexes.
oby position (store the i th value we read at index i )
otally (if input value is i, store it at array index i )
oexplicit mapping (count 'J' at index 0, count 'X' at index 1)
• Exercise: Modify the Sections program to use static methods that
use arrays as parameters and returns.
55. Array param/return answer
import java.io.*;
import java.util.*;
public class Sections2 {
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File("sections.txt"));
int section = 1;
while (input.hasNextLine()) {
// process one section
String line = input.nextLine();
int[] points = countPoints(line);
double[] grades = computeGrades(points);
results(section, points, grades);
section++;
}
}
// Produces all output about a particular section.
public static void results(int section, int[] points, double[] grades) {
System.out.println("Section " + section);
System.out.println("Student scores: " + Arrays.toString(points));
System.out.println("Student grades: " + Arrays.toString(grades));
System.out.println();
}
56. Array param/return answer
// Computes the points earned for each student for a particular section.
public static int[] countPoints(String line) {
int[] points = new int[5];
for (int i = 0; i < line.length(); i++) {
int student = i % 5;
int earned = 0;
if (line.charAt(i) == 'y') { // c == 'y' or c == 'n'
earned = 3;
} else if (line.charAt(i) == 'n') {
earned = 2;
}
points[student] = Math.min(20, points[student] + earned);
}
return points;
}
// Computes the percentage for each student for a particular section.
public static double[] computeGrades(int[] points) {
double[] grades = new double[5];
for (int i = 0; i < points.length; i++) {
grades[i] = 100.0 * points[i] / 20.0;
}
return grades;
}
}