Download presentation
Presentation is loading. Please wait.
1
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu https://xliu12.mysite.syr.edu/
2
Procedure public static void main(String[] args) { int number; … ABC (number) … } Private static void ABC (int targetnum) { … }
3
Concept of Procedures and Functions All modern programming languages have a way to break the program into smaller pieces by placing a piece of code in a procedure or function – This type of modularization is good programming design – Often entire sections of code need to be repeated in different parts of the program, for example sorting a list of data, and making it into a procedure streamlines the process Write once, use many times Java calls these methods
4
Method definition public static int squareR ( int y) { // variable to hold the square of y int ysquared; ysquared = y * y; return ysquared; } scope keywordsreturn typemethod nameformal parameter list method header method body
5
Procedure – organize your code public static void main(String[] args) { String query = “???”; String results; …… results = search (query); results = rank (results); show_results(results); … } private static String search (String query) { String results; … return results; }
6
Wine or water? public static void main(String[] args) { String drink; int age = ??; if (oldenough(age)) { drink = “wine”; } else { drink = “water”; } oldenough(age) Returns a boolean result
7
1+2+3+4+5…100 public static void main(String[] args) { int result = 0; int start = 1; int end = 100; result = sumnums (start, end); System.out.println(result); } sumnums (start, end) Returns int
8
Convert temperature public static void main(String[] args) { double Fahrenheit, Celsius = ??; Fahrenheit = convert_temp (Celsius ); System.out.println(Fahrenheit ); } convert_temp (Celsius ) Returns double
9
Practice 2 + 4 + 6 + 8 … 1000 3 + 6 + 9 + 12 … 1500 public static int sumnum (int startnum, int endnum, int intervalnum) { int number = startnum; int result = 0; while (number < endnum) { result = result + number; number = number + intervalnum; } return result; }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.