CIS October 19, 2017

Similar documents
CIS March 1, 2018

CIS October 16, 2018

Some Practice Midterm Problems

CIS November 14, 2017

CIS November 14, 2017

CIS 1068 Netflix Challenge New assignment posted soon Lab grades November 14, 2017

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

Administrative Stuff CIS Last Time. Midterm 2 today in-lab this week dups. Assignment 10. November 27, 2018

CIS November 27, 2018

1. Find the output of following java program. class MainClass { public static void main (String arg[])

University of Palestine. Mid Exam Total Grade: 100

CSE 142 Sample Midterm Exam #3

Question: Total Points: Score:

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

CS212 Midterm. 1. Read the following code fragments and answer the questions.

BSc (Hons) Computer Science with Network Security/ BSc (Hons) Software Engineering/ BSc (Hons) Web Technologies. Examinations for 2016 Semester 1

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

Introduction to Computer Science Unit 2. Exercises

CSC240 Static method, array, and loop.

COMPUTER APPLICATIONS

I. True/False: (2 points each) On your bubble form fill out a for true and b for false.

Lecture Set 4: More About Methods and More About Operators

Some Sample AP Computer Science A Questions - Solutions

16. Give a detailed algorithm for making a peanut butter and jelly sandwich.

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

AP COMPUTER SCIENCE A

int x = 42, y = 33; //1 int z = x + y; //2 System.out.println(x + "+" + y + "=" + z); //3

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Programming Basics. Digital Urban Visualization. People as Flows. ia

CSE 142 Sample Midterm Exam #3

Selenium Class 9 - Java Operators

Building Java Programs

Term 1 Unit 1 Week 1 Worksheet: Output Solution

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008

Following is the general form of a typical decision making structure found in most of the programming languages:

Java Identifiers, Data Types & Variables

Chapter 7: Iterations

Lara Technologies Special-Six Test

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Contents. 8-1 Copyright (c) N. Afshartous

d. If a is false and b is false then the output is "ELSE" Answer?

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

Course Outline. Introduction to java

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

1. What is the difference between a compiler and an interpreter? Also, discuss Java s method.

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination

Solutions to Sample JAC444 Midterm Test

1. Short circuit AND (&&) = if first condition is false then the second is never evaluated

CSE 114 Computer Science I

Object-Oriented Programming

CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

CMP 326 Midterm Fall 2015

Faculty of Science COMP-202A - Foundations of Computing (Fall 2015) - All Sections Midterm Examination

Building Java Programs

Fundamentals of Programming Data Types & Methods

CSE142 Sample Midterm, Winter 2018

CSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013

Datatypes, Variables, and Operations

Darrell Bethea May 10, MTWRF 9:45-11:15 AM Sitterson 011

1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 4, 2005

1. An operation in which an overall value is computed incrementally, often using a loop.

Building Java Programs

Building Java Programs

I. True/False: (2 points each)

Review Ch 5 static Multiple Choice Test Creating Class Methods

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements

CS 152 Computer Programming Fundamentals The if-else Statement

Lecture Set 4: More About Methods and More About Operators

b. Suppose you enter input from the console, when you run the program. What is the output?

Prof. Navrati Saxena TA: Rochak Sachan

TESTING AND DEBUGGING

1.Which four options describe the correct default values for array elements of the types indicated?

MSCIT (I st Semester) Q1. Solve all parts on answer sheet attached. ( =45 Points) Part 1: Choose valid option for each of the following?

1 Short Answer (10 Points Each)

Section 2.2 Your First Program in Java: Printing a Line of Text

CS141 Programming Assignment #6

JAVA OPERATORS GENERAL

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Zheng-Liang Lu Java Programming 45 / 79

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

Section 2.2 Your First Program in Java: Printing a Line of Text

Nested Loops ***** ***** ***** ***** ***** We know we can print out one line of this square as follows: System.out.

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2010

Programming with Java

CS 112 Introduction to Programming

CS 112 Introduction to Programming

Visual Programming. Lecture 2: More types, Methods, Conditionals

Lesson 36: for() Loops (W11D1)

Exercises Software Development I. 05 Conversions and Promotions; Lifetime, Scope, Shadowing. November 5th, 2014

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Chapter 3. Selections

Midterm Examination (MTA)

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

Transcription:

CIS 1068 October 19, 2017

Administrative Stuff String methods due tomorrow Boston Accent Reading: up to chapter 5 Midterms

Last Time midterm discussion guessing game

Legal Identifiers Ch33zyHaX0R cous cous 5GuysBurgerCount

Legal Identifiers Ch33zyHaX0R yes cous cous 5GuysBurgerCount

Legal Identifiers Ch33zyHaX0R yes cous cous yes 5GuysBurgerCount

Legal Identifiers Ch33zyHaX0R yes cous cous yes 5GuysBurgerCount no

True-False question It s legal to have variables named whitewalkername and WhiteWalkerName in the same program, but not defined in the same method.

True-False question It s legal to have variables named whitewalkername and WhiteWalkerName in the same program, but not defined in the same method. answer False. Java is case sensitive whitewalkername and WhiteWalkerName are different bad idea but legal

What s Printed? 1 public class WhatsPrinted { 2 public static void main(string args[]) { 3 func(0); 4 } 5 6 public static void func(int start) { 7 for (int i=start; i>=0; i--) { 8 System.out.print(i); 9 } 10 } 11 }

What s Printed? 1 public class WhatsPrinted3 { 2 public static void ifelse(int a, int b) { 3 if (a < b) { 4 a++; 5 } 6 if (a < b) { 7 a++; 8 } else { 9 b++; 10 } 11 if (a >= b) { 12 b = b - 5; 13 } 14 System.out.println(a + "," + b); 15 } 16 public static void main(string args[]) { 17 ifelse(10,5); 18 ifelse(3,9); 19 } 20 }

Question About how much is a terabyte? Answer 10 12 or 2 40 or about a trillion bytes

Which analogy is most accurate? cookie cutter is to cookie as object is to class cookie is to cookie cutter as object is to class cookie cutter is to cookie as blueprint is to object cookie is to cookie cutter as blueprint-class is to class cookie is to cookie cutter as base class is to object

What s Printed? 1 public class WhatsPrinted1 { 2 public static void main(string args[]) { 3 int y=10; 4 5 func(y); 6 System.out.println(y); 7 } 8 9 public static void func(int x) { 10 x*=2; 11 } 12 }

What s Printed? 1 public class WhatsPrinted5 { 2 public static int func(int y) { 3 return y*2; 4 } 5 6 public static void main(string args[]) { 7 int x=10; 8 9 func(x); 10 System.out.println(x); 11 } 12 }

What s Printed? 1 public class WhatsPrinted2 { 2 public static void main(string args[]) { 3 int nx=0; 4 for (int i=0; i<5; i++) { 5 for (int j=0; j<3; j++) { 6 if ((i+j)%2==0) { 7 nx++; 8 } 9 } 10 } 11 // last value of j 12 System.out.println(j); 13 } 14 }

What s Printed? 1 public class WhatsPrinted4 { 2 public static void func(int x, int y, int z) { 3 x++; 4 y+=z%2; 5 z*=2; 6 System.out.println(z); 7 } 8 9 public static void main(string args[]) { 10 int x=10, y=21, z=30; 11 12 func(y, z, x); 13 } 14 }

1 public class WhatsPrinted10 { 2 public static void main(string args[]) { 3 yetanotherfunc(); 4 System.out.println(); 5 } 6 7 public static void anotherfunc() { 8 somefunc(); 9 System.out.print("b"); 10 } 11 12 public static void yetanotherfunc() { 13 somefunc(); 14 System.out.print("c"); 15 anotherfunc(); 16 } 17 18 public static void somefunc() { 19 System.out.print("a"); 20 } 21 }

What s Printed? 1 public class WhatsPrinted01 { 2 public static void func(int x, int y, int z) { 3 x+=y/2; 4 z++; 5 y%=3; 6 } 7 8 public static void main(string []args) { 9 int x=10, y=20, z=30; 10 func(z, x, y); 11 System.out.println(x); 12 } 13 }

Question What s the most important job of the Java compiler? Answer To translate my code into more primitive instructions

What s Printed? 1 public class WhatsPrinted08 { 2 public static void main(string args[]) { 3 String s1="bob"; 4 String s2="lob"; 5 String s3="law"; 6 7 for (int i=0; i<5; i++) { 8 if (i%2==0) 9 s2+=s3; 10 else 11 s1+=s2; 12 } 13 System.out.println(s1); 14 } 15 }

Expression Evaluation 516 / 10 / 5 / 2.0 * 2 + 14 / 5

Expression Evaluation 2.5 * 2 * 5 / 10 + 1.5

Expression Evaluation "hard".charat(0) + "exam".substring(2,4);

Expression Evaluation 1 + 2 + "." + (3 + 4) + 5 * 6

Expression Evaluation!(2<7%2*3 5%10>=5+3)

Expression Evaluation 72 % 10 + 2 % 5-9 % 4

Expression Evaluation 11 + 2 * 5 / 2

Question Translate each of the following statements from English to Java. For example, if the English is x is larger than 10, you d write the Java expression x > 10. Assume that we already have int x, int y, and the String s and String t already properly declared somewhere else in our program. t does not occur in s Answer s.indexof(t)==-1 OR!s.contains(t)

Question Translate each of the following statements from English to Java. For example, if the English is x is larger than 10, you d write the Java expression x > 10. Assume that we already have int x, int y, and the String s and String t already properly declared somewhere else in our program. The sum of x and y is odd. Answer (x+y)%2==1

Question Translate each of the following statements from English to Java. For example, if the English is x is larger than 10, you d write the Java expression x > 10. Assume that we already have int x, int y, and the String s and String t already properly declared somewhere else in our program. s is longer than 10 characters and begins with the letter F Answer s.length()>10 && s.beginswith("f") or s.length()>10 && s.charat(0)== F

Question Write the few lines of code that print the integers between 50 and 10000 that are evenly divisible by 7 (i.e. 56, 63, 70, 77, 84,... ).

Question Write the few lines of code that print the integers between 50 and 10000 that are evenly divisible by 7 (i.e. 56, 63, 70, 77, 84,... ). Answer for (int i=50; i<=10000; i++) { if (i%7==0) { System.out.print(i + " "); } }

Question Write a method called printtri( ) that takes an integer numlines as an argument. The method prints a triangle which is numlines high with the following format: if numlines=1: if numlines=3: if numlines=3: etc. 1 1 22 1 22 333

Question Write a method called printtri( ) that takes an integer numlines as an argument. The method prints a triangle which is numlines high with the following format: if numlines=1: if numlines=3: if numlines=3: etc. 1 Answer 1 22 1 22 333 public static void printtri(int numlines) { for (int i=1; i<=numlines; i++) { for (int j=1; j<=i; j++) { System.out.print(i); } System.out.println(); } }

Question Write a method which is passed an integer n. The method returns the sum of all of the positive integers from 1 to n. For example, if n is 5, the method returns 15, because 15 is 1 + 2 + 3 + 4 + 5. You do not have to write a complete class. You do not have to use a Scanner to read user input from the keyboard.

Question Write a method which is passed an integer n. The method returns the sum of all of the positive integers from 1 to n. For example, if n is 5, the method returns 15, because 15 is 1 + 2 + 3 + 4 + 5. You do not have to write a complete class. You do not have to use a Scanner to read user input from the keyboard. Answer public static final int sumton(int n) { int sum=0; } for (int i=1; i<=n; i++) { sum+=i; } return sum;