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 <

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

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
For(int i = 1; i
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 {
Chapter 3A Review boolean fun = true; if(fun) System.out.print(“yeah!”);
What is output line of the following C++ code? Please trace int i = 1, QP; DATA: 4, B, 3, A double credit, totCredit=0.0; double num = 0.0; string LG;
Computer Programming Lab(7).
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);
Interfaces CSC 171 FALL 2004 LECTURE 14. Project 1 review public class Rational { private int numerator, denominator; public Rational(int numerator, int.
Revision.
Hand Trace and Output for: int digit = 0; int number = 1423; do { digit = number % 10; System.out.println(digit); number = number / 10; } while (number.
Public class ABC { private int information = 0; private char moreInformation = ‘ ‘; public ABC ( int newInfo, char moreNewInfo) { } public ABC () {} public.
CSCI 160 Midterm Review Rasanjalee DM.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Sort the given string, without using string handling functions.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. Multithreading Example from Liang textbook.
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
ISQA 360 – July 8, 2002 Methods Dr. Sergio Davalos.
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Indentation & Readability. What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println(
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
Take out a piece of paper and PEN. The quiz starts ONE minute after the tardy bell rings. You will have 45 – 90 seconds per question. Determine the output.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Converting string to integer class StringToInt { public static void main (String arg[]) { // Assume arg[0] is the input string int result = 0, pos; int.
 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.
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Java Scanner Class Keyboard Class. User Interaction So far when we created a program there was no human interaction Our programs just simply showed one.
Output Programs These slides will present a variety of small programs. Each program has a compound condition which uses the Boolean Logic that was introduced.
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.
Checking character case class characterCase { public static void main (String arg[]) { char c = ‘A’; if (isUpperCase(c)) { System.out.println(c + “ is.
Recursion occurs when a method calls itself. Google “recursion”
Output Programs These slides will present a variety of small programs. Each program has a control structure that was introduced in this chapter. Our concern.
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.
1 Towers of Hanoi Three pegs, one with n disks of decreasing diameter; two other pegs are empty Task: move all disks to the third peg under the following.
1 Advanced Programming Examples. using System; class Test { static void Main( string[] args ) { int a = 7; int b = 3; int c = 5; int d = 9; Console.WriteLine(!(d.
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
Java Methods and Applications CSIS 3701: Advanced Object Oriented Programming.
Introduction of Java Fikri Fadlillah, S.T.
Exercise Java programming
using System; namespace Demo01 { class Program
Sum of natural numbers class SumOfNaturalNumbers {
Maha AlSaif Maryam AlQattan
Method Mark and Lyubo.
Functions Used to write code only once Can use parameters.
Computing Adjusted Quiz Total Score
TO COMPLETE THE FOLLOWING:
Stack Memory 2 (also called Call Stack)
An Introduction to Java – Part I, language basics
בניית מחלקות.
Exception Handling CSCI293 - C# October 3, 2005.
Propositional Equivalences Rosen 5th and 6th Editions section 1.2
160 Exam 2 Prep.
Assignment 7 User Defined Classes Part 2
Code Animation Examples
Recursive GCD Demo public class Euclid {
AKA the birth, life, and death of variables.
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Java for Beginners University Greenwich Computing At School DASCO
Scope of variables class scopeofvars {
Methods and Data Passing
Recursion Method calling itself (circular definition)
Arrays Wellesley College CS230 Lecture 02 Thursday, February 1
Presentation transcript:

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 < 6; i++) for (int j = 0; j < 6; j++) { if ( i == j || i == 0 || i == 5 ) pic[i, j] = '*'; else pic[i, j] = '.'; } for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) console.write(pic[i, j]); console.writeln(“ “); } 2

String a = "alfred"; String b = "fred"; b = "al" + b; if (a == b) a = "fred"; else b = "fred"; 3

int a = 5; int b = 10; a = a + 5; { int a; a = 20; b = b + 5 ; } MessageBox.Show(a+ " " + b) } 4

Assume that the method enigma has been defined as follows: static int enigma(int n) { int m; while (n >= 10) { m = 0; while (n > 0) { m += n % 10; n /= 10; } n = m; } return (n); } What is the value of enigma(1999) ? 5

using System; class Test { static void Main( string[] args ) { int a = 7; int b = 3; int c = 5; int d = 9; Console.WriteLine(!(d == a) || (a < b+c) && (d-c <= b)); } 6