CSCI S-1 Section 11. Coming Soon Problem Set Six (25 + 5 points) – Tuesday, 28 July, 17:00 EST Problem Set Seven (20 points) – Friday, 31 July, 17:00.

Slides:



Advertisements
Similar presentations
Graohics CSC 171 FALL 2001 LECTURE 16. History: COBOL Conference on Data System Languages (CODASYL) - led by Joe Wegstein of NBS developed the.
Advertisements

Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Java Programming Strings Chapter 7.
Computer Programming Lab 8.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
CMT Programming Software Applications
Introduction to Computers and Programming Lecture 10: For Loops Professor: Evan Korth New York University.
1 Data types, operations, and expressions Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions.
Introduction to Computers and Programming Lecture 3: Variables and Input Professor: Evan Korth New York University.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Some basic I/O.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Unit 171 Algorithms and Problem Solving - II Algorithm Efficiency Primality Testing Improved Primality Testing Sieve of Eratosthenes Primality Testing.
Sanjay Goel, School of Business, University at Albany, SUNY 1 MSI 692: Special Topics in Information Technology Lecture 4: Strings & Arrays Sanjay Goel.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Recursion & Collections API Recursion Revisited Programming Assignments using the Collections API.
Forth A stack language.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
Characters The data type char represents a single character in Java. –Character values are written as a symbol: ‘a’, ‘)’, ‘%’, ‘A’, etc. –A char value.
Chapter 4 Numeration and Mathematical Systems © 2008 Pearson Addison-Wesley. All rights reserved.
When we add or subtract integers we can use a number line to help us see what is happening with the numbers.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CSC Programming I Lecture 5 August 30, 2002.
Arrays Part 9 dbg. Arrays An array is a fixed number of contiguous memory locations, all containing data of the same type, identified by one variable.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Jaeki Song ISQS6337 Lecture 01 Introduction. Jaeki Song ISQS6337 Instructor Name: Jaeki Song Office: BA 712 Office Hours Tuesday & Thursday 2:00-3:20.
CSCI S-1 Section 6. Coming Soon Homework Part A – Friday, July 10, 17:00 EST Homework Part B – Tuesday, July 14, 17:00 EST Mid-Term Quiz Review – Friday,
Lab 07: Caesar Cypher Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
CS 121 – Intro to Programming:Java - Lecture 7 Announcements A new Owl assignment is available. Programming assignment 4 is due on Thursday - hand in on.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Java Expressions MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh.
VARIABLES Programmes work by manipulating data placed in memory. The data can be numbers, text, objects, pointers to other memory areas, and more besides.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
Cryptography.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Array Declarations Arrays contain a fixed number of variables of identical type Array declaration and allocation are separate operations Declaration examples:
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
Sum of Arithmetic Sequences. Definitions Sequence Series.
Ch 3.1 Add and Subtract Signed Numbers Vocabulary Op posites :2 numbers the same distance from 0 but in opposite directions
Pointers A pointer type variable holds the address of a data object or a function. A pointer can refer to an object of any one data type; it cannot refer.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
A Sample Program #include using namespace std; int main(void) { cout
Midterm 2 Review Notes on the CS 5 midterm Take-home exam due by 5:00 pm Sunday evening (11/14) Hand in your solutions under the door of my office, Olin.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
2.5 Another Java Application: Adding Integers
Chapter 6 More Conditionals and Loops
Multiple variables can be created in one declaration
Formatting Output.
IDENTIFIERS CSC 111.
CS 106A, Lecture 9 Problem-Solving with Strings
CMSC 104, Section 4 Richard Chang
Chapter 7: Strings and Characters
Final Exam.
Encryption and Decryption
Expressions and Assignment Statements
Recursion Problems.
Just Enough Java 17-May-19.
Presentation transcript:

CSCI S-1 Section 11

Coming Soon Problem Set Six ( points) – Tuesday, 28 July, 17:00 EST Problem Set Seven (20 points) – Friday, 31 July, 17:00 EST Exam Review – Monday, 3 August, 15:15 EST Final Exam – Wednesday, 5 August, 15:15 EST PS 6 Office Hours Tonight – Sever Hall, room 106

Caesar Cipher You have an integer key k and a text T and you want to rotate all the letters in T by k. What is the encryption for k=3 and a text of “ABCD”? Java represents characters internally as numbers, so you may achieve the desired effect by converting the character to an integer, adding k to it, and converting back to a char. What is the encryption for k=3 and a text of “ZzZz”? If you simply add k to 'Z', you will not get 'C’ -- you need to circle around and get back to the beginning, paying attention to whether the letter is uppercase or lowercase What arithmetic operator helps you circle back around?

Vigenere Cipher For Vigenere, the idea is similar except the key is not an integer but rather a word. If the keyword is "ABCD“, Vigenere will encrypt by shifting the first letter by 0, the second by 1, the third by 2, the fourth by 3, the fifth by 0, the sixth by 1, and so on in a cyclic manner. The trick is to compute the shift equivalent of each letter (e.g., 'a' corresponds to a shift of 0, 'b' to a shift of 1, etc) and cycling through the keyword to get the current shift amount. Other than that, things are pretty similar to Caesar.

Useful Char Methods Character.isLetter - takes a character and returns true if the character ch is a letter. Character.isLowerCase - takes a character and returns true if the character ch is lowercase. Character.isUpperCase - takes a character and returns true if the character ch is uppercase.

Exercise Exercise: Write a method that takes a string, replaces all uppercase letters with a + (plus) and all lowercase letters with a - (minus), and returns the modified string. All characters that are not letters should be left unchanged.

upperPlusLowerMinus public static String upperPlusLowerMinus(String inString) { }

upperPlusLowerMinus public static String upperPlusLowerMinus(String inString) { String outString = ""; char ch; for(int i = 0; i < inString.length(); i++) { ch = inString.charAt(i); if (Character.isLetter(ch)) if (Character.isUpperCase(ch)) outString += “+"; else outString += “-"; else outString += Character.toString(ch); } return outstring; }

BigInteger For very large numbers java.sun.com/javase/6/docs/api/java /math/BigInteger.html java.sun.com/javase/6/docs/api/java /math/BigInteger.html Import java.math.BigInteger; BigInteger num = new BigInteger(" "); BigInteger num2 = new BigInteger("3");

BigInteger Methods num.isProbablePrime(certainty) returns true if num is prime with certainty (1 - 1/2^certainty) and false if it is definitely not prime num.remainder(num2) returns num % num2 as a BigInteger num.compareTo(num2) returns -1, 0 or 1 as num is less than, equal to, or greater than num2 num.add(number2) returns sum of num, num2 num.toString() converts BigInteger back into a String.

BigInteger Exercise // print all nine-digit numbers that are divisible by import java.math.BitInteger; Public static void main (String [] args) { BigInteger divnum = new BigInteger(" "); }

BigInteger Exercise // print all nine-digit numbers that are divisible by import java.math.BitInteger; Public static void main (String [] args) { BigInteger divnum = new BigInteger(" "); final BigInteger ONE = new BigInteger("1"); final BigInteger ZERO = new BigInteger("0"); for (BigInteger i = new BigInteger(" "), BigInteger j = new BigInteger(" "); j.compareTo(i) >= 0; i=i.add(ONE)) { BigInteger result = i.remainder(divnum); if (result.compareTo(ZERO) == 0) System.out.println(i.toString()); }