Functions Used to write code only once Can use parameters.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

1 Classes and Objects in Java Parameter Passing, Delegation, Visibility Control, and Object Cleanup.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Copyright © Recursive GCD Demo public class.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
Programming Methodology (1). Implementing Methods main.
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
Tinaliah, S. Kom.. * * * * * * * * * * * * * * * * * #include using namespace std; void main () { for (int i = 1; i
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
תכנות ב C#. דוגמא לפלט using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void.
Distributed Systems Tutorial 1 - Getting Started with Visual C#.NET.
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
Methods & Activation Record. Recap: what’s a method?
C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.
Features of Object Oriented Programming:  A class is a collection of things which posses common similarities.  In C#.NET a class is a user defined.
Refactoring An Automated Tool for the Tiger Language Leslie A Hensley
ILM Proprietary and Confidential -
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Indentation & Readability. What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println(
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
Java Programming Final Keyword In Java. final keyword The final keyword in java is used to restrict the user. The final keyword can be used in many context.
 A class is a collection of things which posses common similarities.  In C#.NET a class is a user defined Data type and is Known as Reference.
Wel come To Seminar On C#.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
Chapter 5 : Methods Part 2. Returning a Value from a Method  Data can be passed into a method by way of the parameter variables. Data may also be returned.
C# - Inheritance Ashima Wadhwa. Inheritance One of the most important concepts in object- oriented programming is inheritance. Inheritance allows us to.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
JAVA METHODS (FUNCTIONS). Why are they called methods? Java is a strictly object-oriented programming language Methods are functions inside of objects.
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
Recursion occurs when a method calls itself. Google “recursion”
Recursion occurs when a method calls itself. public class RecursionOne { public void run(int x) { System.out.println(x); run(x+1); } public static void.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Import javax.swing.JOptionPane; public class Rectangle { public static void main(String[] args) { double width, length, area, perimeter; String lengthStr,
Staples are our staple Building upon our solution.
Comp1004: Building Better Objects I Methods. Coming up Methods and Parameters – Why Parameterise? – Call by value, call by reference Return Types – Methods.
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
Building C# Applications
AKA the birth, life, and death of variables.
התוכנית: using System; using System.Collections.Generic;
using System; namespace Demo01 { class Program
Sum of natural numbers class SumOfNaturalNumbers {
RADE new features via JAVA
Introduction to C# AKEEL AHMED.
Computing Adjusted Quiz Total Score
TO COMPLETE THE FOLLOWING:
Exception Handling CSCI293 - C# October 3, 2005.
عرض اجمالي المهام الشرطية في سي شارب (الأمر if)
Code Animation Examples
References, Objects, and Parameter Passing
Example with Static Variable
Recursive GCD Demo public class Euclid {
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
AKA the birth, life, and death of variables.
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Java Programming with Multiple Classes
if-else if (condition) { statements1 } else { statements2
Scope of variables class scopeofvars {
Chapter 13 Exception Handling: A Deeper Look
Methods and Data Passing
CSE Module 1 A Programming Primer
Var Name =Console . ReadLine();
Module 4 Loops and Repetition 4/15/2019 CSE 1321 Module 4.
CS1S467 GUI Programming LECTURE 14 Methods (1 of 2)
Scope scope: The part of a program where a variable exists. From its declaration to the end of the { } braces A variable declared in a for loop exists.
Methods/Functions.
MIS 222 – Lecture 12 10/9/2003.
Presentation transcript:

Functions Used to write code only once Can use parameters

using System; namespace Demo01 { class Program static void Main(string[] args) string name = "world"; int year = 2017; for (int i = 0; i < 10; i++) PrintYear(name, i + year); } private static void PrintYear(string name, int year) Console.WriteLine("Hello " + name + ", the year is " + year);

string name = "Loek"; Console.WriteLine(name); name = "Antje"; int year = 2017; for (int i = 0; i < 10; i++) { // everything that happens here, happens 10 times Console.WriteLine("Hello " + name + " the current year is " + (year + i)); }

Condition

int startYear = 2010; for (int i = 0; i < 10; i++) { int year = startYear + i; if (year == 2017) Console.WriteLine(year + " is the current year"); } else Console.WriteLine(year + " is NOT the current year");

int startYear = 2010; for (int i = 0; i < 10; i++) { int year = startYear + i; if (year == 2017) Console.WriteLine(year + " is the current year"); } else if (year < 2017) Console.WriteLine(year + " is before the current year"); else Console.WriteLine(year + " is after the current year");

int startYear = 2010; for (int i = 2010; i < 2020; i++) { int year = startYear + i; if (year == 2017) Console.WriteLine(year + " is the current year"); } else if (year < 2017) Console.WriteLine(year + " is before the current year"); else Console.WriteLine(year + " is after the current year");

Methods

Console.WriteLine("+======================================+"); Console.WriteLine("Hello, my name is: LOEK"); Console.WriteLine(""); Console.WriteLine("Hello, my name is: LEO"); Console.WriteLine("Hello, my name is: PIET");

static void Main(string[] args) { Console.WriteLine("Atendee list"); Console.WriteLine("––––––––––––––––––––––"); Console.WriteLine(""); PrintName("Karl"); PrintName("Petra"); } static void PrintName(string name) Console.WriteLine(name);