2012.10.19. Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice.

Slides:



Advertisements
Similar presentations
IS Programming Fundamentals 1 (Lec) Date: September 14, Array.
Advertisements

CS Network Programming CS 3331 Fall CS 3331 Outline Socket programming Remote method invocation (RMI)
Java Control Statements
Solve problems with Java code Algorithms with Java.
I/O Basics 12 January 2014Smitha N. Pai, CSE Dept.1.
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.
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.
Basic Java Constructs and Data Types – Nuts and Bolts
1 Streams and Input/Output Files Part 2. 2 Files and Exceptions When creating files and performing I/O operations on them, the systems generates errors.
1 Streams and Input/Output Files Part 3. 2 Handling Primitive Data Types The basic input and output streams provide read/write methods that can be used.
Taking Input Java Md. Eftakhairul Islam
Iterations for loop. Outcome Introduction to for loop The use of for loop instead of while loop Nested for loops.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Procedural Programming in C# Chapters Objectives You will be able to: Describe the most important data types available in C#. Read numeric values.
1 Todays Objectives Announcements Homework #1 is due next week Return Quiz 1 – answers are posted on the Yahoo discussion page site Basic Java Programming.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Copyright © Recursive GCD Demo public class.
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
Lecture 15: I/O and Parsing
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
Simple Programs Simple Strings Writing some programs Only in Parameters? I/O Gadget.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
© 2007 Lawrenceville Press Slide 1 Chapter 5 The if Statement  Conditional control structure, also called a decision structure  Executes a set of statements.
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);
Chapter 10 Ch 1 – Introduction to Computers and Java Streams and File IO 1.
MOD III. Input / Output Streams Byte streams Programs use byte streams to perform input and output of 8-bit bytes. This Stream handles the 8-bit.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 3: Program Statements 3.6 – Iterators – p
Lecture 8 Instructor: Craig Duckett. Assignments TONIGHT Lecture 8 Assignment 2 Due TONIGHT Lecture 8 by midnight Monday, February 2 nd Lecture 10 Assignment.
Chapter 3 Flow of Control Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Logical and Relational Operation Session 5 Course: T-0974 Algorithm & Object-Oriented Programming I Year: 2010.
Formal Language, chapter 4, slide 1Copyright © 2007 by Adam Webber Chapter Four: DFA Applications.
LYNBROOK COMPUTER SCIENCE CLUB MONDAY, OCTOBER 26, 2009 POWERPOINT CREATED BY: RITIK MALHOTRA PRESENTATION BY: KARTHIK VISWANATHAN Intro to USACO.
Graohics CSC 171 FALL 2001 LECTURE 16. History: COBOL Conference on Data System Languages (CODASYL) - led by Joe Wegstein of NBS developed the.
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.
Craps. /* * file : Craps.java * file : Craps.java * author: george j. grevera, ph.d. * author: george j. grevera, ph.d. * desc. : program to simulate.
CS110 Programming Language I
주사위 게임 주사위 2개를 가지고 하는 게임 작성 주사위 굴리는 건 랜덤 값으로 처리 플레이어 선택 => 키보드 입력
Java Programming Strings Chapter 7.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.1 Chapter 3 Selections.
Computer Programming Lab 8.
Logic & program control part 3: Compound selection structures.
1 Fall 2009ACS-1903 The break And continue Statements a break statement can be used to abnormally terminate a loop. use of the break statement in loops.
1 Repetition structures Overview while statement for statement do while statement.
Some basic I/O.
Reading Information From the User Making your Programs Interactive.
1 Streams Overview l I/O streams l Opening a text file for reading l Reading a text file l Closing a stream l Reading numbers from a text file l Writing.
1 Fall 2008ACS-1903 for Loop Reading files String conversions Random class.
Chapter 3 Selections Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1.
Java Exception Handling Handling errors using Java’s exception handling mechanism.
1 Course Lectures Available on line:
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.1 Chapter 3 Selections.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.1 Chapter 3 Selections.
Console Input. So far… All the inputs for our programs have been hard-coded in the main method or inputted using the dialog boxes of BlueJ It’s time to.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
© 2005 Lawrenceville Press Slide 1 Chapter 5 Relational Operators Relational OperatorMeaning =greater than.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. CHAPTER 3: SELECTIONS 1.
1 Chapter 3 Selections. 2 Outline 1. Flow of Control 2. Conditional Statements 3. The if Statement 4. The if-else Statement 5. The Conditional operator.
OOP (pre) Basic Programming. Writing to Screen print will display the string to the screen, the following print statement will be appended to the previous.
Using Java Class Library
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
CSCI 1100/1202 January 23, Class Methods Some methods can be invoked through the class name, instead of through an object of the class These methods.
Introduction to programming in java
I/O Basics.
SELECTION STATEMENTS (1)
Operators Laboratory /11/16.
Relational, Logical, and Equality Operators
Chapter 3 Selections Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Exception Handling Contents
Presentation transcript:

Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice

import java.io.* ; public class InputStr{ public static void main(String[] args) throws java.io.IOException { BufferedReader keyin = new BufferedReader(new InputStreamReader(System.in)); // keyin String str = keyin.readline(); // keyin System.out.println(str); }

import java.util.Scanner; public class scan { public static void main(String[] args) throws Exception{ Scanner keyin = new Scanner(System.in); String str = keyin.nextLine(); System.out.print(str); }

if(num%2==0){ System.out.println(Even number); } else{ System.out.println(Old number); };

if(num%2==0){ System.out.println(Even number!!); System.out.println(num = +num); } else { System.out.println(Old number!!); System.out.println (num = +num); }

Error 1: if ( radius >= 0 ) area = radius * radius * 3.14; System.out.println(The area is + area);

if ( radius >= 0 ) { area = radius * radius * 3.14; System.out.println(The area is + area); }

Error 2: if ( radius >= 0 ); { area = radius * radius * 3.14; System.out.println(The area is + area); }

if ( radius >= 0 ); { area = radius * radius * 3.14; System.out.println(The area is + area); }

Error 3: if ( a = true ) { System.out.println(a is true !! ); }

if ( a == true ) { System.out.println(a is true !! ); }

OperatorNameDescription !notlogical negation &&andlogical conjunction ||orlogical disjunction ^exclusive orlogical exclusive

num = 1 num = 2 else Statement 1 Statement else Statement 2 true false

switch (num) { case 1:statement 1; break; case 2:statement 2; break; default:statement else; System.exit(0); }

import java.io.*; public class Season2Wear { public static void main(String[] argv) throws IOException { System.out.println(" "); System.out.print(" "); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = br.readLine(); int season = Integer.parseInt(str); switch (season) { case 1: // season 1 System.out.println(" "); break; // case case 2: // season 2 System.out.println(" "); break; // case case 3: // season 3 System.out.println(" "); break; // case case 4: // season 4 System.out.println(" "); break; // case }

import java.util.Scanner; public class SubtractionQuiz{ public static void main(String[] args){ int number1=(int)(Math.random()*10); int number2=(int)(Math.random()*10); if(number1<number2){ int temp =number1; number1=number2; number2=temp; System.out.print("What is "+number1+" - "+number2+" ? "); Scanner input new Scanner(System.in); int answer =input.nextInt(); if(number1-number2==answer){ System.out.println("You are correct!!"); }else{ System.out.println("Your answer is wrong\n"+number1+"-"+number2+"is"+(number1- number2)); }

1., 2. 90~100 A; 80~89 B; 70~79 C; 60~69 D;0~60 E( ) ( switch)

3.Write a program that prompts the user to enter a,b,c,d,e and f and displays the result. If ad-bc is 0,report that The equation has no solution. 4.Write a program that simulates picking a card from a deck of 52 cards. Your program should display the rank(Ace,2,3,4,5,6,7,8,9,10,Jack,Queen,King) and suit(Clubs,Diamonds,Hearts,Spades) of the card.

Ppt