Something about Java Introduction to Problem Solving and Programming 1.

Slides:



Advertisements
Similar presentations
CS102--Object Oriented Programming Discussion 2: (programming strategy in java) – Two types of tasks – The use of arrays Copyright © 2008 Xiaoyan Li.
Advertisements

Java Syntax. Basic Output public class test1 { public static void main(String[] args) { System.out.println("Hello"); }
Important Notes Pay attention to file names!!! You must name them what we tell you to. mkdir – make a folder (make the ones we tell you to) rm – remove.
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.
Scanner & Stepwise Refinement Pepper With credit to Dr. Siegfried.
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.
LAB 10.
Computer Programming Lab(4).
Computer Programming Lab(5).
The for-statement. Different loop-statements in Java Java provides 3 types of loop-statements: 1. The for-statement 2. The while-statement 3. The do-while-statement.
JAVA Control Structures: Repetition. Objectives Be able to use a loop to implement a repetitive algorithm Practice, Practice, Practice... Reinforce the.
COMP 110 Spring Announcements Computers in class on Friday: Lab Office Hours: Monday 12-2 New students see me after class Administrative Changes.
COMP 110: Introduction to Programming Tyler Johnson January 14, 2009 MWF 11:00AM-12:15PM Sitterson 014.
Catie Welsh January 12, 2011 MWF 1-1:50 pm Sitterson
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
Java TA Session 1. Software Java Runtime Environment (JRE) java.exe Java Development Kit (JDK) java.exe, javac.exe Version 1.6 = Version 6, Version 1.7.
Input & Output In Java. Input & Output It is very complicated for a computer to show how information is processed. Although a computer is very good at.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) public static void main(String[]
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.
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.
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I 12/11/20151.
Using the while-statement to process data files. General procedure to access a data file General procedure in computer programming to read data from a.
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.
Reading input from the console input. Java's console input The console is the terminal window that is running the Java program I.e., that's the terminal.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I 2/4/20161.
Computer Programming1 Computer Science 1 Computer Programming.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Switch Statement.
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.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
1 Simple Input Interactive Input - The Class Scanner n Command-Line Arguments.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 6_1 GEORGE KOUTSOGIANNAKIS Copyright: FALL 2015 Illinois Institute of Technology- George Koutsogiannakis 1.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING For Loop.
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
Common Mistakes with Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Day Programming with Methods. The “do” loop The “do” loop is a type of while loop that only does one iteration (does one loop at least) It is hardly.
Variable scope. Variable Scope Variables do not live forever. Failing to take that into account leads to problems. Let's look at an example. Let's write.
CS0007: Introduction to Computer Programming
Chapter 2 Clarifications
CSC111 Quick Revision.
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.
CSC1401 Input and Output (and we’ll do a bit more on class creation)
Software Development Packages
CSC305: COMPUTER PROGRAMMING II (JAVA)
5.1 Programming with Methods
Computer Programming Methodology Input and While Loop
Introduction to Methods in java
Repetition.
Data types, Expressions and assignment, Input from User
TK1114 Computer Programming
Comp Sci 200 Programming I Jim Williams, PhD.
BIT115: Introduction to Programming
While Statement.
Computing Adjusted Quiz Total Score
Michele Weigle - COMP 14 - Spr 04
Computers & Programming Languages
Introduction to Classes and Methods
Java so far Week 7.
class PrintOnetoTen { public static void main(String args[]) {
Week 4 Lecture-2 Chapter 6 (Methods).
Introduction to Java Brief history of Java Sample Java Program
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Scope of variables class scopeofvars {
while while (condition) { statements }
Consider the following code:
Presentation transcript:

Something about Java Introduction to Problem Solving and Programming 1

Parts of a program Structure Code Action Code Comments – Directions to the human on how to read the program 2

Object-Oriented Programming Programmers – Write classes – Use objects Java is Object-Oriented – We will write at least one class for every problem 3

} // end main() public static void main(String[] args) { public class FirstProgram { }// end FirstProgram 4 Every program in Java is a class We name the class (same name as the file) One class has a method named “main” it is the start

import java.util.Scanner; System.out.println("Please enter two numbers and"); System.out.println("I will compute their sum."); int n1; int n2; int sum; Scanner keyboard = new Scanner(System.in); n1 = keyboard.nextInt(); n2 = keyboard.nextInt(); System.out.println("Their sum is"); System.out.println(sum); }// end main() public static void main(String[] args) { public class FirstProgram { }// end FirstProgram Scanner class is in another package (and we want to use it) Inform the user Declare variables Prepare to read from the keyboard Show the user the answer 5 Get the input sum = n1 + n2; Do the math

import java.util.Scanner; System.out.println("Please enter two numbers and"); System.out.println("I will compute their sum."); int n1; int n2; int sum; Scanner keyboard = new Scanner(System.in); n1 = keyboard.nextInt(); n2 = keyboard.nextInt(); System.out.println("Their sum is"); System.out.println(sum); }// end main() public static void main(String[] args) { public class FirstProgram { }// end FirstProgram 6 sum = n1 + n2; Comments begin // (these are not typical comments)