Java so far Week 7.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 4: September 12-16, 2011 Aditya Mathur/Tim Korb Department of Computer.
Some basic I/O.
Java Intro. Strings “This is a string.” –Enclosed in double quotes “This is “ + “another “ + “string” –+ concatenates strings “This is “ “ string”
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
MSc IT Programming Methodology (2). MODULE TEAM Dr Aaron Kans Dr Sin Wee Lee.
JAVA PROGRAMMING PART II.
Conditional If Week 3. Lecture outcomes Boolean operators – == (equal ) – OR (||) – AND (&&) If statements User input vs command line arguments.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Java Fundamentals 3 Input and Output statements. Standard Output Window Using System.out, we can output multiple lines of text to the standard output.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
Chapter 2: Java Fundamentals
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.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) public static void main(String[]
COMP 110 switch statements and while loops Luv Kohli September 10, 2008 MWF 2-2:50 pm Sitterson
Primitive data Week 3. Lecture outcomes Primitive data – integer – double – string – char – Float – Long – boolean Declaration Initialisation Assignments.
Repetition Statements while and do while loops
COMP Flow of Control: Branching 1 Yi Hong May 19, 2015.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
FUNDAMENTALS 2 CHAPTER 2. OPERATORS  Operators are special symbols used for:  mathematical functions  assignment statements  logical comparisons 
Week 3 - Friday.  What did we talk about last time?  Operations on boolean values  !, &&, ||  Operations on char values  +, -  Operations on String.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
Java Variables, Types, and Math Getting Started Complete and Turn in Address/Poem.
1 More data types Character and String –Non-numeric variables –Examples: char orange; String something; –orange and something are variable names –Note.
1.2 Built-in Types of Data Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008 · December.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
Java Scanner Class Keyboard Class. User Interaction So far when we created a program there was no human interaction Our programs just simply showed one.
© 2007 Lawrenceville Press Slide 1 Chapter 4 Review Assignment Statement An assignment statement gives a value to a variable. Assignment can take several.
Copyright © Curt Hill Simple I/O Input and Output using the System and Scanner Objects.
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 Simple Input Interactive Input - The Class Scanner n Command-Line Arguments.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Object Oriented Programming Lecture 2: BallWorld.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
CompSci 230 S Programming Techniques
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
Chapter 2 Clarifications
Crash course in the Java Programming Language
Elementary Programming
Chapter 2 Elementary Programming
Yanal Alahmad Java Workshop Yanal Alahmad
CS116 OBJECT ORIENTED PROGRAMMING II LECTURE 1 Part II
Introduction to programming in java
Data types, Expressions and assignment, Input from User
Chapter 5: Control Structures II
SELECTION STATEMENTS (1)
Something about Java Introduction to Problem Solving and Programming 1.
An Introduction to Java – Part I
INPUT STATEMENTS GC 201.
TO COMPLETE THE FOLLOWING:
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
An Introduction to Java – Part I, language basics
Java Variables, Types, and Math Getting Started
Self study.
class PrintOnetoTen { public static void main(String args[]) {
Building Java Programs
Lecture Notes – Week 2 Lecture-2
Java Programming Review 1
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Introduction to java Part I By Shenglan Zhang.
More on iterations using
Presentation transcript:

Java so far Week 7

What we should know by now Print statement System.out.print(); Primitive data Int, float, double, long, String, char, boolean, Variable declaration int x ; or int x=1; Concatenation “Hello” + “hellow” = “Hellohello” Arithmetic and Boolean expressions Artithmetic (6+2), (6-2), 6/2, 6%2 , ..... Boolean (1==(3-2)), (3>=2), (3<=2), ((3%2)==1) Assignment statements Int x , y , z; x =1; y=2, y= x+1 ; The use of arguments Command line argument are by default parsed as string, Int x = Integer.parseInt(args[0]); double x = Integer.parseDouble(args[0]) Keyboard interaction with the use of Scanner. Scanner input = new Scanner(System.in); String x = input.nextLine(); Int x = input.nextInt(); Double x = input.nextDouble(); If statements If (true ) then {statments1} else {statments2}

The random class Random is defined in the "java.util" library package, so any Java source file that uses Random must begin with a line of the form import java.util.Random; or import java.util.*;

Creating Random Number Generators The easiest way to initialize a random number generator is to use Random generator = new Random(); Int x = generator.nextInt(); // generate negative and positive integers Int x = generator.nextInt(n); // generate an integer between 0 and n (0 inclusive and n exclusive). Int x = generator.nextInt(95) + 5 ; // generate an integer between 5 and 100 double x = generator.nextDouble(); // generate an double number between 0 and 1.

Example import java.util.Random; class MyRandom { public static void main(String [] args) Random generator = new Random(); int x = generator.nextInt(); // random integer System.out.println(x); int y = generator.nextInt(100); //random integer x ( 0<= x<100) System.out.println(y); int t = generator.nextInt(95)+5; // random number betweein 5 and 100 System.out.println(t); double z = generator.nextDouble(); // random doube between 0 and 1 System.out.println(z); }

Home Work A set of simple exercises can be downloadable from you web site Do please do all these exercises before the 19th of November.