CS110D Programming Language I

Slides:



Advertisements
Similar presentations
CS110 Programming Language I
Advertisements

Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Your First Java Program: HelloWorld.java
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Methods: a first introduction Two ways to make tea: 1: boil water; put teabag into cup;... etc : tell your younger brother: makeTea(1 milk, 0 sugar);
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;
“Introduction to Programming With Java”
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Laboratory Study October, The very first example, traditional "Hello World!" program: public class first { public static void main (String[ ]
Basics Programming Concepts. Basics A computer program is a set of instructions to tell a computer what to do Machine language = circuit level language.
Welcome to the Lecture Series on “Introduction to Programming With Java”
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
BUILDING JAVA PROGRAMS CHAPTER 2 Days of For Loops Past.
Chapter 2: Java Fundamentals
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Variables, Arithmetic, etc.)
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
CSC1030 HANDS-ON INTRODUCTION TO JAVA Introductory Lab.
Java Basics Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,
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.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.
CS001 Introduction to Programming Day 6 Sujana Jyothi
Simple Console Output. What we will briefly discuss System.out.println( … ) System.out.print( … ) System.out.printf( … )
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Primitive data types Lecture 03. Review of Last Lecture Write a program that prints the multiplication table of 5. class MultiplicationTable { public.
Testing and Debugging UCT Department of Computer Science Computer Science 1015F Hussein Suleman March 2009.
Introduction to programming in java
Computer Programming Your First Java Program: HelloWorld.java.
CompSci 230 S Programming Techniques
John Woodward A Simple Program – Hello world
Exercise Java programming
Building Java Programs
Chapter 6 More Conditionals and Loops
Maha AlSaif Maryam AlQattan
Primitive Data, Variables, Loops (Maybe)
Intro to Java.
OUTPUT STATEMENTS GC 201.
Tonga Institute of Higher Education
Building Java Programs
Building Java Programs
AP Java Review If else.
Java Intro.
Building Java Programs
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
AP Java Review If else.
Java Programming with BlueJ Objectives
Building Java Programs
Building Java Programs
Unit 3: Variables in Java
Building Java Programs
Debugging Exercise 00 Try compiling the code samples.
Building Java Programs
Building Java Programs
Presentation transcript:

CS110D Programming Language I Lab 2 : Java basics I Computer Science Department Fall 2017

Lab Exercise 1: program output Lab Objectives: In this lab, the student will practice: Using System.out.print , System.out.println, output text and characters to the command window. Compiling and executing Java applications. Writing and evaluating mathematical expressions Debugging code and System.out.printf to Lab Exercise 1: program output Problem Description What is output by the following programs? // Lab Exercise 1: hello.java // Printing with multiple statements public class Hello { // main method begins execution of Java application public static void main( String args[] ) System.out.print("HELLO WORLD, "); System.out.println("I am a new programmer :)"); System.out.println("\"Programming is fun\""); System.out.printf("\"%s%s\"","Programming is ","fun"); } // end method main } // end class hello Output :

Output : // Lab Exercise 1: Math.java // Computing and displaying the result of different expressions public class Math { // main method begins execution of Java application public static void main( String args[] ) System.out.print("((2-2) × 1×3) - 3/1.0= "); System.out.println(((2-2)*1*3)-3/1.0); System.out.println("4.0*1="+4.0*1); System.out.println("4.0+1="+4.0+1); System.out.println("4.0+1="+(4.0+1)); } // end main } // end class Math Output :

Lab Exercise 2: debugging Problem Description The following code segments do not compile. Fix all the compilation errors so that the program will compile successfully. (4 errors in every code) // Lab Exercise 2: information.java // Printing with multiple statements public class information { // main method begins execution of Java application public static void main( String args[] ); System.out.print("My name is Ahmad); System.out.print(); }// end information class Correct code:

Correct code: // Lab Exercise 2: hello.java // Printing with a printing statement public hello { // main method begins execution of Java application public static void main( String args[] ) system.out.println("HELLO everybody!"); }// end hello class Correct code:

Lab Exercise 3: calculate squares and cubes Problem Description Write an application that calculates and prints the squares and cubes of the integers from 0 to 5. Sample output Code Skelton:

Lab Exercise 4: Shape Problem Description Code Skelton: Write java program that prints the following shape: Code Skelton:

Assignment Problem(s) Q1: More shape 1. Write a program that it prints the shape. The should have a side containing 8 asterisks. Code Skelton:

Q2: Program output Output: What is the expected output of the following program: // Lab.2 Q.2: Homework.java // Program that prints the result of remainder operators public class Homework2 { public static void main (String args[]) System.out.print("The remainder of 40%7% 8="); System.out.println(40%7%8); } // end main } // end Homework2 Output: