CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.

Slides:



Advertisements
Similar presentations
Computer Programming Lab(7).
Advertisements

CS110 Programming Language I
Computer Programming Lab 8.
CS110 Programming Language I Lab 10: Arrays I Computer Science Department Spring 2014.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
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.
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.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: *Sample Development Loan Calculator.
Loops Chapter 4. It repeats a set of statements while a condition is true. while (condition) { execute these statements; } “while” structures.
TA: Nouf Al-Harbi NoufNaief.net :::
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
Scanner & Stepwise Refinement Pepper With credit to Dr. Siegfried.
Java Overview CS2336: Computer Science II1. First Program public class HelloWorld { public static void main(String args[]) { System.out.println("Hello.
Writing algorithms using the while-statement. Previously discussed Syntax of while-statement:
Writing algorithms using the for-statement. Programming example 1: find all divisors of a number We have seen a program using a while-statement to solve.
CS212: DATASTRUCTURES Lecture 3: Searching 1. Search Algorithms Sequential Search It does not require an ordered list. Binary Search It requires an ordered.
LAB 10.
Computer Programming Lab(4).
Computer Programming Lab(5).
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Lesson 7: Improving the User Interface
 The pool rack example could be implemented using a for loop.  It is also possible to write recursive methods that accomplish things that you might.
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
Chapter 2 Elementary Programming
1 Fencepost loops “How do you build a fence?”. 2 The fencepost problem Problem: Write a class named PrintNumbers that reads in an integer called max and.
Chapter 5 Case Study. Chapter 5 The RPS Flowchart.
 Executes a block of code repeatedly  A condition controls how often the loop is executed  Most commonly, the statement is a block statement (set of.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
1 while loops. 2 Definite loops definite loop: A loop that executes a known number of times.  The for loops we have seen so far are definite loops. We.
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:
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.
Computer Programming1 Computer Science 1 Computer Programming.
 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.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Switch Statement.
C OMMON M ISTAKES CSC Java Program Structure  String Methods.
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.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
Computer Programming Lab 6. Exercise 1 Sample Runs.
A.P. Computer Science Input is NOT tested on the AP exam, but if we want to do any labs, we need input!!
INF120 Basics in JAVA Programming AUBG, COS dept Lecture 07 Title: Methods, part 1 Reference: MalikFarrell, chap 1, Liang Ch 5.
Chapter 2 Clarifications
CSC111 Quick Revision.
Software Development I/O and Numbers
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.
TemperatureConversion
Chapter 2 Elementary Programming
Maha AlSaif Maryam AlQattan
Computer Programming Methodology Input and While Loop
Data types, Expressions and assignment, Input from User
TK1114 Computer Programming
Comp Sci 200 Programming I Jim Williams, PhD.
Something about Java Introduction to Problem Solving and Programming 1.
While Statement.
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Introduction to Computer Science and Object-Oriented Programming
AP Java Review If else.
Self study.
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
AP Java Review If else.
Building Java Programs
Random Numbers while loop
Consider the following code:
Computer Science Club 1st November 2019.
Presentation transcript:

CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014

here is the new site:

What is output by the following programs? import java.util.Scanner; public class lab5_1 { public static void main(String args[]) { Scanner input = new Scanner(System.in); System.out.print("Enter a decimal value (0 to 15): "); int decimal = input.nextInt(); // the user will enter 12 if (decimal > 15 || decimal < 0) System.out.println("Invalid input"); else if (decimal 1-) System.out.println("The hex value is " + decimal); else System.out.println("The hex value is " + (char)('A' + decimal - 10)); }

Problem Description Write a program that convert currency from U.S. dollars $ to Saudi riyal SR or vice. Prompt the user to enter 1 to convert from $ to SR 0 to convert from SR and $. Prompt the user to enter the amount to convert it to what she chose Sample output:

Code Skelton

Follow-up Questions and Activities Try to modify the last code from Switch to If statements.

Evaluation By using Switch write a program that prompt the user to enter a character between A and C and display the arrangement of this character If the user enter something else print (Invalid input) Sample output: Enter a letter from A to C: C The arrangement of this character is 3