

2024-06-23
Presentation
•
Computers
•
11th Grade
•
Practice Problem
•
Easy
Arasaka Teacher
Used 1+ times
FREE Resource
1 Slide • 5 Questions
1
9618-paper2
By Arasaka Teacher
2
Open Ended
public class AlgorithmExample {
public static void main(String[] args) {
int[] data1 = {1, 2, 3, 4};
int[] data2 = {5, 6, 7, 8};
// 计算 data1 的平方和
int sum1 = 0;
for (int num : data1) {
sum1 += num * num;
}
System.out.println("data1 的平方和: " + sum1);
// 计算 data2 的平方和
int sum2 = 0;
for (int num : data2) {
sum2 += num * num;
}
System.out.println("data2 的平方和: " + sum2);
}
}
3
Drag and Drop
The calculateSquareSum method can be called anywhere in the program without
If the calculation logic needs modification (e.g., changing to cube sum num num num), only the calculateSquareSum method needs adjustment,
The main program logic becomes clearer and easier to understand, as complex algorithms are abstracted into dedicated methods.
4
Reorder
————————:
Look at the code that is used in many places and does the same calculation.
————————:
Create a new method (or function) and put the repeated code inside it.
Make sure this method can take different data, such as an array of numbers.
————————:
Let the method give back the result of the calculation so the rest of the program can use it.
————————:
Replace the old repeated code with calls to the new method.
Send the needed data to the method when calling it.
——:
Verify that the new method works correctly with various inputs.
Ensure that the overall program behaves as expected after the modification.
Find the Repeated Code
Make a New Method
Return the Result
Use the New Method
Test and Validate
5
Dropdown
List the Variables:
Write down all variables you will use. For example:
declare A, B, C
Initialization:
Remember to initialize variables. For example:
initialize A to 0
2.
Identify Needed Structures:
Decide if you need an array, a record, or a file. For example:
declare an array called Numbers
or
declare a record called Student
3.
Loops and Repetition:
Describe how the loop works. For example:
For Loop: “set a
If your program uses a file, include steps like:
open file in read mode
read data from the file
close the file
6
Dropdown
Assignment and Calculation:
For assignment, use words like “set” or “assign”.
Example: “assign A to B”
For addition: “calculate the new value of C by adding A to B”
For subtraction: “calculate the new value of C by subtracting A from B”
For multiplication: “calculate the new value of C by multiplying A by B”
For division: “calculate the new value of C by dividing A by B”
Example: “obtain the new string by concatenating A with B, and assign the new string to Variable2.”
Prompting the User:
Always include a prompt when the program should ask for user input.
Example: “display prompt 'Enter a number:'”
5.
Write “end while” or “next i” after the loop to show it ends.
Always indicate when a block of instructions is finished.
6. Using Functions (if any)
Call Functions Clearly:
Example: “use the function INT() to obtain the whole number part of the digit.”
9618-paper2
By Arasaka Teacher
Show answer
Auto Play
Slide 1 / 6
SLIDE
Similar Resources on Wayground
3 questions
INFORMATIKA
Presentation
•
12th Grade
6 questions
Ανάπτυξη Ιστοτόπων
Presentation
•
12th Grade
6 questions
Reading Comprehension activity
Presentation
•
University
8 questions
TIPE DATA PHYTON
Presentation
•
11th Grade
8 questions
Párrafo
Presentation
•
11th Grade
6 questions
GD - Hoover
Presentation
•
11th Grade
6 questions
math addition
Presentation
•
KG
Popular Resources on Wayground
24 questions
PBIS-HGMS Day 10
Quiz
•
6th - 8th Grade
10 questions
HCS SCI 03 Summer School Review 3
Quiz
•
3rd Grade
11 questions
Home Scope
Quiz
•
7th - 8th Grade
15 questions
HCS SCI 05 Summer School Assessment 3 Review
Quiz
•
5th Grade
35 questions
Lufkin Road Middle School Student Handbook & Policies Assessment
Quiz
•
7th Grade
18 questions
Geo 11.3 Area of Circles and Sectors
Quiz
•
9th - 11th Grade