חלק ה שימוש במציין שלם לערך תווי

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

Ics202 Data Structures. import java.util.Scanner; public class Name { static int Algorithm Name (int n) { … The Algorithm … } public static void main.
Hand Crafting your own program By Eric Davis for CS103.
CSCI S-1 Section 5. Deadlines for Problem Set 3 Part A – Friday, July 10, 17:00 EST Parts B – Tuesday, July 14, 17:00 EST Getting the code examples from.
CSCI S-1 Section 7. Coming Soon Problem Set Three, Part B – Tuesday, July 14, 17:00 EST Problem Set Four (72 + 5/15 points) – Friday, July 17, 17:00 EST.
Introduction to Computer Programming Decisions If/Else Booleans.
Scanner Pepper With credits to Dr. Siegfried. The Scanner Class Most programs will need some form of input. At the beginning, all of our input will come.
Copyright 2006 by Pearson Education 1 reading: 4.1 Cumulative sum.
Loops –For For Reading for this Lecture, L&L, Part of 5.8.
Scanner & Stepwise Refinement Pepper With credit to Dr. Siegfried.
LAB 10.
Computer Programming Lab(4).
1 Scanner objects. 2 Interactive programs We have written programs that print console output. It is also possible to read input from the console.  The.
1 BUILDING JAVA PROGRAMS CHAPTER 3 THE SCANNER CLASS AND USER INPUT.
Computer Programming Lab(5).
Java Fundamentals 3 Input and Output statements. Standard Output Window Using System.out, we can output multiple lines of text to the standard output.
Chapter 5 Case Study. Chapter 5 The RPS Flowchart.
Input/Output in Java. Output To output to the command line, we use either System.out.print () or System.out.println() or System.out.printf() Examples.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) public static void main(String[]
The if StatementtMyn1 The if Statement The basic if statement allows your program to execute a single statement, or a block of statements enclosed between.
The if-else statement. The if-else statement in Java The if-else statement is the second conditional statement in Java The if-else statement selects one.
CSC1401 Strings (text). Learning Goals Working with Strings as a data type (a class) Input and output of Strings String operations.
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
CHAPTER 5 GC 101 Input & Output 1. INTERACTIVE PROGRAMS  We have written programs that print console output, but it is also possible to read input from.
Truth and while Today 15 Minutes online time to finish the random/Swing programs. Truth tables: Ways to organize results of Boolean expressions. Note Taking:
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Cumulative algorithms. 2 Adding many numbers How would you find the sum of all integers from ? // This may require a lot of typing int sum = 1 +
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
SELF STUDY. IF STATEMENTS SELECTION STRUCTURE if selection statement if … else selection statement switch selection statement.
Library Books exercise cosc The classes Library class +ArrayList -ArrayList + Library() +initializeDefaultCategories():void +displayAllCategories():void.
 CSC111 Quick Revision. Problem Write a java code that read a string, then show a list of options to the user to select from them, where:  L to print.
CSCI S-1 Section 8. Coming Soon Problem Set Four (72 + 5/15 points) – Tuesday, July 21, 17:00 EST.
C OMMON M ISTAKES CSC Java Program Structure  String Methods.
Floating Point ValuestMyn1 Floating Point Values Internally, floating point numbers have three pairs: a sign (positive or negative), a mantissa (has a.
CS001 Introduction to Programming Day 6 Sujana Jyothi
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
WAP to find out the number is prime or not Import java.util.*; Class Prime { public static void main(string args[]) { int n,I,res; boolean flag=true;
A.P. Computer Science Input is NOT tested on the AP exam, but if we want to do any labs, we need input!!
Introduction to programming in java
Programación I Estructuras de control Java. IF- Else.
Staples are our staple Building upon our solution.
Three kinds of looping structures The while loop The for loop The do (also called the do-while) loop All have equivalent power, e.g., if you can write.
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
Chapter 2 Clarifications
Exercise 1- I/O Write a Java program to input a value for mile and convert it to kilogram. 1 mile = 1.6 kg. import java.util.Scanner; public class MileToKg.
using System; namespace Demo01 { class Program
Chapter 2 Elementary Programming
Switch Statement.
Repetition.
TK1114 Computer Programming
Something about Java Introduction to Problem Solving and Programming 1.
פונקציות קרן כליף.
Decision statements. - They can use logic to arrive at desired results
The for-loop and Nested loops
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
ניתוח זמן ריצה (על קצה המזלג)
Java Language Basics.
The Basics of Recursion
Recursive GCD Demo public class Euclid {
Self study.
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Module 4 Loops and Repetition 4/7/2019 CSE 1321 Module 4.
Building Java Programs
Building Java Programs
Random Numbers while loop
Consider the following code:
More on iterations using
Instructor: Mainak Chaudhuri
Presentation transcript:

חלק ה שימוש במציין שלם לערך תווי מערך חד מימדי חלק ה שימוש במציין שלם לערך תווי

דוגמה פתורה עמ 37-38 קלט: 100 אותיות a..z פלט: האות הכי שכיחה אותיות שלא הופיעו בקלט

ניתוח מציין למערך הוא מספר שלם כמה איברים במערך? מה כל איבר מייצג? 26 מה כל איבר מייצג? שכיחות של כל אות: מספר הפעמים שהופיעה בקלט איך נתאים בין מספר שלם(מציין) לאות? 26 25 24 ..... 2 1 z y x c b a

תת משימות איפוס מערך מונים עבור כל 100 האותיות קליטת אות מניית מופע של האות מציאת האות השכיחה ביותר והצגתה כפלט הצגה בפלט של אותיות שלא הופיעו בקלט

משתנים שם טיפוס הסבר טווח ערכים letters מערך חד מימדי שלמים מערך מונים לשמירת שכיחות של כל אות 0..100 ch תו תו הקלט a..z max מציין של האיבר המקסימלי במערך 0..25

static Scanner reader = new Scanner(System.in); public static void main(String[] args) { int max, N=26; int[] letters = new int[N]; char ch, maxLet; for (int i=0 ; i<N ; i++) letters[i] = 0; for (int i=0 ; i<100 ; i++) System.out.println("Enter a letter"); ch = reader.next().charAt(0); letters[ch-'a']++; }

max = 0; for (int i=1 ; i< letters.length ; i++) if (letters[i]>letters[max]) max = i; maxLet = (char)(max+'a'); System.out.println("The most frequent letter is "+ maxLet); System.out.println("The letters that did not appear are:"); for (int i=0 ; i< letters.length ; i++) if (letters[i]==0) System.out.println( (char)(i+'a')); }

letters[ch-'a']++; ניתן לבצע פעולות חשבון על תווים. תו זה טיפוס עם סדר: a < b < c < d …. x< y < z לכל אות יש ערך מספרי ההפרש המספרי בבין אותיות סמוכות: 1

maxLet = (char)(max+'a');

ש"ב עמ 39-40 תרגילים 41-43