Week #2 Java Programming. Enable Line Numbering in Eclipse Open Eclipse, then go to: Window -> Preferences -> General -> Editors -> Text Editors -> Check.

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

Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Switch Statement. Nested IF-ELSE Statement if (month == 1) { mString="January"; } else if (month == 2) { mString=“February”; } else if (month == 3) {
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
COMP 14 Introduction to Programming Miguel A. Otaduy May 19, 2004.
15-Jun-15 Beginning Style. 2 Be consistent! Most times, you will enter an ongoing project, with established style rules Follow them even if you don’t.
How to Create a Java program CS115 Fall George Koutsogiannakis.
CS 106 Introduction to Computer Science I 01 / 29 / 2008 Instructor: Michael Eckmann.
Loops – While, Do, For Repetition Statements Introduction to Arrays
Introduction to Python
Function tax and buy_one double tax (double price, double tr) { return price*tr; } double buy_one() { double p; cout > p;
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 1, 2005.
The If/Else Statement, Boolean Flags, and Menus Page 180
Computer Science A 1: 3/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
Chapter 2 Section 2.2 Console Input Using The Scanner CLASS Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska.
Week #2 Java Programming. Enable Line Numbering in Eclipse Open Eclipse, then go to: Window -> Preferences -> General -> Editors -> Text Editors -> Check.
Its all just code by group 8 张亚东,杨杰,甘伟,余青龙,肖春亮 chapter 2.
Java Programming Constructs 1 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Chapter 3:Decision Structures.  3.1 The if Statement  3.2 The if-else Statement  3.3 The if-else-if Statement  3.4 Nested if Statements  3.5 Logical.
Agenda Review C++ Library Functions Review User Input Making your own functions Exam #1 Next Week Reading: Chapter 3.
Chapter 2: Java Fundamentals
Hey, Ferb, I know what we’re gonna do today! Aims: Use formatted printing. Use the “while” loop. Understand functions. Objectives: All: Understand and.
CSE1222: Lecture 6The Ohio State University1. Common Mistakes with Conditions (1)  Consider the following code: int age(26); if (age = 18) { cout
Decision Making Selection structures (if....else and switch/case)
CS115 Math Class. Printing Out The command : System.out.println(“ Something that we want to print out on the screen as output”); Prints out in one line.
Chapter 3- Flow Control. Overview n Why flow control n Branches vs. Loops n Branch statements n Loop Statements n Complex loops n Boolean variables n.
CS Class 05 Topics  Selection: switch statement Announcements  Read pages 74-83, ,
Please log on The. AN INTRODUCTION TO ‘Python is a high-level, general purpose programming language’ Python is one of the many programming languages.
CSC1030 HANDS-ON INTRODUCTION TO JAVA Introductory Lab.
ECE 122 Feb. 1, Introduction to Eclipse Java Statements Declaration Assignment Method calls.
VARIABLES Programmes work by manipulating data placed in memory. The data can be numbers, text, objects, pointers to other memory areas, and more besides.
Condition & loop Android Club Agenda if/else Switch Loops.
Decisions, Decisions, Decisions Conditional Statements In Java.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Conditionals Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignment? zPass by value limitations.
By Mr. Muhammad Pervez Akhtar
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
BOOLEAN OPERATIONS AND CONDITIONALS CHAPTER 20 1.
Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.
GCSE Computing: Programming GCSE Programming Remembering Python.
Decision Making and Branching
Chapter 2: Fundamental Programming Structures in Java Adapted from MIT AITI Slides Control Structures.
Slides prepared by Rose Williams, Binghamton University Console Input and Output.
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Control Structures- Decisions. Smart Computers Computer programs can be written to make computers seem smart Making computers smart is based on decision.
Lecture 4 CS140 Dick Steflik. Reading Keyboard Input Import java.util.Scanner – A simple text scanner which can parse primitive types and strings using.
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
More about comments Review Single Line Comments The # sign is for comments. A comment is a line of text that Python won’t try to run as code. Its just.
Chapter 2, Part I Introduction to C Programming
Engineering Innovation Center
SELECTION STATEMENTS (1)
Java Programming with BlueJ
Govt. Polytechnic,Dhangar
Python programming exercise
Selection Statements Chapter 3.
Unit 1: Intro Lesson 4: Output.
Chapter 1 c++ structure C++ Input / Output
Arrays Introduction to Arrays Reading for this Lecture:
Presentation transcript:

Week #2 Java Programming

Enable Line Numbering in Eclipse Open Eclipse, then go to: Window -> Preferences -> General -> Editors -> Text Editors -> Check “Show Line Numbers”

Simple Output For printing words (or Strings) onto the screen, we use this command: System.out.println(“Anything you want printed here”); If we want to print something that contains a variable, we would use this command: String mySentence = “Hey there.”; System.out.println(mySentence);

Simple Output String commands: \”This represents a quotation mark \’This represents an apostrophe \nThis represents a new line \\This represents a backslash \tThis represents a tab \sThis represents a space

Simple Output Another way to print out text onto your screen: This is used when you have a lot of variables to be included in the print statement, example: String name = “Vincent Tsang”; int age = 60; String school = “Binghamton University”; System.out.format(“My name is %s, I am %s years old, I go to %s.”, name, age, school);

Simple Output Printing out variables using the System.out.println(“”); format: String name = “Vincent Tsang”; int age = 60; String school = “Binghamton University”; System.out.println(“My name is ” + name + “. I am “ + age + “years old, I go to “ + school + “.”);

If/Else Statements What is an if/else statement? Basically, in programming, we will often have different ways to approach things depending on the values given to it. We tell the program that “If something occurs, do this. If something else occurs, do something else. Else do something else” T his will be clearer when we write out the code

If/Else Statements The command for the if/else statement is in this format: if(comparison) { Something happens here; } else { Something else happens here; }

If/Else Statements You are allowed to have more than one if statement: if(comparison) { Something happens here; } if(comparison2) { Something else happens here; } else { Something else happens here; }

If/Else Statements Nested If/Else Statements: if(comparison) { if(comparison2) {// Basically the same as && symbol Something happens here; } } else { Something else happens here; }

If/Else Statements Logical Operators || represents “or” This can be found above your enter key (it’s located with the backslash) && represents “and” This can be found with the 7 key Switch Statements This is used when you have a lot of things to compare and do different type of commands This is to save time so that you don’t have to type out a billion if statements

If/Else Statements In a switch statement, we need a variable to compare its value with: Example: int month;// This is our integer variable switch(month) { case 1: System.out.println(“January”); break; // We will always need to break out of the statement case 2: System.out.println(“February”); break; } Do Exercise 1 (Age.java)