Day 2 : Intermediate Concepts 1 Examples
|
|
- Blanche McBride
- 5 years ago
- Views:
Transcription
1 Example1 Day 2 : Intermediate Concepts 1 Examples public class Example1 public static void main(string[] args) int a= 5, b = 10, c = 15, d= 20; Assignment int x = a++; a is assigned to x and then increment System.out.println(x); End result: x = 5, a = 6 System.out.println(a); int x = ++b; b is incremented and then assigned to x System.out.println(x); End result: x = 5, a = 6 System.out.println(b); End result: b = 11, x = 11 int x = c--; c assigned to x and then decremented System.out.println(x); End result: x = 5, a = 6 System.out.println(c); End result: x= 15, c = 14 int x = --d ; End result d = 19, x= 19 System.out.println(x); End result: x = 5, a = 6 System.out.println(d); int x= -a; x = -5 System.out.println(x); End result: x = 5, a = 6 System.out.println(a); Example 2 Example 3 public class Example2 public static void main(string[] args) System.out.println(4.5<=10); System.out.println(4.5<-10); System.out.println(-35>=0); System.out.println(10<=4+6); System.out.println(35==35); System.out.println(22!=10); public class Example3 public static void main(string[] args) int x= 10, y = 20; boolean z ; z = x>y; System.out.println(z); Prints false
2 Example 4 public class Example4 public static void main(string[] args) int a = 1, b= 2; if(a>b) a=0; else b=0; System.out.println("a : "+a); System.out.println("b : "+b); Example 5 public class Example5 public static void main(string[] args) int a =8; if( a>0) if(a%2==0) System.out.println("Even Positive Number"); else System.out.println("Positive Odd Number"); else System.out.println("Negative Number"); System.out.println("Success! Exiting "); Example 6 public class Example6 public static void main(string[] args) int marks = 60; String grade; if (marks > 79) grade = "Honours"; else if(marks> 59) grade = "First Division"; else if(marks > 49) grade = "Second Division"; else if(marks > 39) grade = "Third Division"; else grade = "Fail"; System.out.println("Grade is : "+grade);
3 Example 7 public class Example7 public static void main(string[] args) int month=4; String season; switch(month) case 1: case 2: case 12: season = "Winter"; break; case 3: case 4: case 5: season = "Spring"; break; case 6: case 7: case 8: season = "Summer"; break; default: season = "Invalid Month"; System.out.println("April is in the "+season); Example 8 public class Example8 public static void main(string[] args) int x= 1; while(x<=5) System.out.println("The value of x is :" +x); x++; Example 9 public class Example9 public static void main(string[] args) int x= 1; do System.out.println("The value of x is :" +x); x++;
4 while(x<=5); Example 10 public class Example10 public static void main(string[] args) int x; for( x=1; x<=5;x++) System.out.println("Count is :" +x); System.out.println("Statement outside loop"); Example 11 public class Example11 public static void main(string[] args) boolean t = true; first: second: System.out.println(" Before the break"); if(t) break second; System.out.println("This won't execute"); System.out.println("After second block"); Example 12 public class Example12 public static void main(string[] args) int i; for(i=0;i<10;i++) if(i%2==0) continue; System.out.println(i + " "); Example 13 public class Example13 public static void main(string[] args) boolean t= true; System.out.println("Before the return"); if(t) return; System.out.println("After the return");
5 Example 14 public class Employee int empid; public static void main(string[] args) Employee emp1= new Employee(); emp1.empid = 001; emp1.name = "John"; emp1.dept = "Production"; System.out.println("Employee Id : " +emp1.empid); System.out.println("Name : " +emp1.name); System.out.println("Department : " +emp1.dept); Example 15 class Employee int empid; void display( ) System.out.println("Employee Id: " + empid); System.out.println("Name : " + name); System.out.println("Department : " + dept); public static void main(string[] args) Employee emp1= new Employee(); emp1.empid = 001; emp1.name = "John"; emp1.dept = "Production"; emp1.display( ); Example 16 Employee emp2= new Employee(); emp2.empid = 002; emp2.name = "Mary"; emp2.dept = "Testing"; emp2.display( );
6 Example 17 class Employee int empid; void accept(int id, String n, String d) Formal Parameters empid = id; name = n; dept = d; void display( ) System.out.println("Employee Id: " + empid); System.out.println("Name : " + name); System.out.println("Department : " + dept); public static void main(string[] args) Employee emp1= new Employee(); Employee emp2= new Employee(); emp1.accept(001, "John ", "Production "); emp2.accept(002, " Mary ", "Testing "); emp1.display( ); emp2.display( ); Example 18 class Employee int empid; void accept(int id, String n, String d) empid = id; name = n; dept = d; void accept(int id, String n) empid = id; name = n; void display( ) System.out.println("Employee Id: " + empid);
7 System.out.println("Name : " + name); System.out.println("Department : " + dept); public static void main(string[] args) Employee emp1= new Employee(); Employee emp2= new Employee(); emp1.accept(001, "John ", "Production"); emp2.accept(002, " Mary " ); emp1.display( ); emp2.display( ); Example 19 class Employee int empid; void accept(int id, String n, String d) empid = id; name = n; dept = d; void accept(int id, String n) empid = id; name = n; void change_basic (int a) a = 12000; void display( ) System.out.println("Employee Id: " + empid); System.out.println("Name : " + name); System.out.println("Department : " + dept); public static void main(string[] args) int basic_sal=15000; Employee emp1= new Employee(); emp1.accept(001, "John", "Production"); emp1.display( );
8 System.out.println("Basic Salary before method call :"+basic_sal); emp1.change_basic(basic_sal); System.out.println("Basic Salary after method call :"+basic_sal); Example 20 class Employee int empid; int basic_sal=10000; void accept(int id, String n, String d) empid = id; name = n; dept = d; void accept(int id, String n) empid = id; dept = d; void change_basic(employee ob) ob.basic_sal = 12000; void display( ) System.out.println("Employee Id: " + empid); System.out.println("Name : " + name); System.out.println("Department : " + dept); EXAMPLE 20.1 public static void main(string[] args) Employee emp1= new Employee(); emp1.accept(001, "John", "Production"); emp1.display( ); System.out.println("Basic Salary before method call: "+emp1.basic_sal); emp1.change_basic(emp1); System.out.println("Basic Salary after method call :"+emp1.basic_sal);
9 Example 22 public class Employee static int empid; static String name; static String dept; static void accept(int id, String n, String d) empid = id; name = n; dept = d; static void display() System.out.println("Employee Id : " +empid); System.out.println("Name : " +name); System.out.println("Department : " +dept); public static void main(string[] args) Employee emp1= new Employee(); emp1.accept(001, " John", "Production"); Employee.accept(001, "John", "Production"); classname.method() System.out.println("Name of the employee :"+Employee.name); System.out.println("Employee Id:" +Employee.empid); Example 23 public class Employee int empid; public Employee() Constructor empid =0; name =" "; dept =" "; public static void main(string[] args) Employee e2=new Employee();
10 Example 24 public class Employee int empid; private Employee() Constructor empid =0; name =" "; dept =" "; public static void main(string[] args) Employee e2=new Employee(); Invalid Example 25 public class Employee int empid; private Employee() Constructor empid =0; name =" "; dept =" "; void main() Employee e1= new Employee(); EXAMPLE 25.1 public static void main(string[] args) Employee e1=new Employee(001, "John", "Production"); Employee e2=new Employee(); Invalid e2.display(); Example 26 class Employee int empid; public Employee(int i, String n, String d)
11 empid = i; name = n; dept = d; void display() System.out.println("Employee Id : " +empid); System.out.println("Name : " +name); System.out.println("Department : " +dept); public static void main(string[] args) Employee e1=new Employee(001, "John", "Production"); Parameterized Employee e2=new Employee(); Non-parameterized e1.display(); e2.display(); Example 27 public class Employee int empid; public Employee() Constructor empid =0; name ="ABC"; dept ="TESTING "; void display() System.out.println("Employee Id : " +empid); System.out.println("Name : " +name); System.out.println("Department : " +dept); public static void main(string[] args) Employee e1=new Employee();
12 Example 28 public class Employee int empid; public Employee() empid=0; name="null"; dept="null"; public Employee(int i, String n, String d) empid=i; name=n; dept=d; void display( ) System.out.println("Employee Id: " + empid); System.out.println("Name : " + name); System.out.println("Department : " + dept); public static void main(string[] args) Employee e1=new Employee(001, "John", "Production"); Parameterized Employee e2=new Employee(); Non-parameterized e1.display(); e2.display();
Java Professional Certificate Day 1- Bridge Session
Java Professional Certificate Day 1- Bridge Session 1 Java - An Introduction Basic Features and Concepts Java - The new programming language from Sun Microsystems Java -Allows anyone to publish a web page
More informationSelenium Class 9 - Java Operators
Selenium Class 9 - Java Operators Operators are used to perform Arithmetic, Comparison, and Logical Operations, Operators are used to perform operations on variables and values. public class JavaOperators
More informationSequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;
Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The
More informationJAVA OPERATORS GENERAL
JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators
More informationFall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.
Grading Page 1 / 4 Page3 / 20 Page 4 / 13 Page 5 / 10 Page 6 / 26 Page 7 / 17 Page 8 / 10 Total / 100 1. (4 points) What is your course section? CS 101 CS 101E Pledged Page 1 of 8 Pledged The following
More informationProf. Navrati Saxena TA: Rochak Sachan
JAVA Prof. Navrati Saxena TA: Rochak Sachan Operators Operator Arithmetic Relational Logical Bitwise 1. Arithmetic Operators are used in mathematical expressions. S.N. 0 Operator Result 1. + Addition 6.
More informationJava provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:
Basic Operators Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators
More informationAP COMPUTER SCIENCE A
AP COMPUTER SCIENCE A CONTROL FLOW Aug 28 2017 Week 2 http://apcs.cold.rocks 1 More operators! not!= not equals to % remainder! Goes ahead of boolean!= is used just like == % is used just like / http://apcs.cold.rocks
More informationLara Technologies Special-Six Test
Flow control Part-1 Q: 01 Given: 10. public class Bar 11. static void foo( int... x ) 12. // insert code here 13. 14. Which two code fragments, inserted independently at line 12, will allow the class to
More informationbitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=
Operators in java Operator in java is a symbol that is used to perform operations. For example: +, -, *, / etc. There are many types of operators in java which are given below: Unary Operator, Arithmetic
More information10/30/2010. Introduction to Control Statements. The if and if-else Statements (cont.) Principal forms: JAVA CONTROL STATEMENTS SELECTION STATEMENTS
JAVA CONTROL STATEMENTS Introduction to Control statements are used in programming languages to cause the flow of control to advance and branch based on changes to the state of a program. In Java, control
More informationTutorial # 4. Q1. Evaluate the logical (Boolean) expression in the following exercise
Tutorial # 4 Q1. Evaluate the logical (Boolean) expression in the following exercise 1 int num1 = 3, num2 = 2; (num1 > num2) 2 double hours = 12.8; (hours > 40.2) 3 int funny = 7; (funny!= 1) 4 double
More informationProgramming Basics. Digital Urban Visualization. People as Flows. ia
Programming Basics Digital Urban Visualization. People as Flows. 28.09.2015 ia zuend@arch.ethz.ch treyer@arch.ethz.ch Programming? Programming is the interaction between the programmer and the computer.
More informationJava Programming for Selenium
Video 5 - Java Control Flow, String Handling and Arrays Java Programming for Selenium 1) Conditional / Decision Making 2) Loop 3) Branching 4) String Handling in Java 5) Java Arrays 1) Conditional / Decision
More informationOperators Questions
Operators Questions https://www.geeksforgeeks.org/java-operators-question-1/ https://www.indiabix.com/java-programming/operators-andassignments/ http://www.instanceofjava.com/2015/07/increment-decrementoperators-interview.html
More informationJava Simple Data Types
Intro to Java Unit 1 Multiple Choice Test Key Java Simple Data Types This Test Is a KEY DO NOT WRITE ON THIS TEST This test includes program segments, which are not complete programs. Answer such questions
More informationCONDITIONAL EXECUTION
CONDITIONAL EXECUTION yes x > y? no max = x; max = y; logical AND logical OR logical NOT &&! Fundamentals of Computer Science I Outline Conditional Execution if then if then Nested if then statements Comparisons
More informationUniversity of Palestine. Mid Exam Total Grade: 100
First Question No. of Branches (5) A) Choose the correct answer: 1. If we type: system.out.println( a ); in the main() method, what will be the result? int a=12; //in the global space... void f() { int
More informationSection 002 Spring CS 170 Exam 1. Name (print): Instructions:
CS 170 Exam 1 Section 002 Spring 2015 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than
More information1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'
Practice questions: 1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4' 2. Will System.out.println((char)4) display 4? a. Yes b. No 3. The expression "Java
More informationFinal. Your Name CS Fall 2014 December 13, points total Your Instructor and Section
Final Your Name CS 1063 - Fall 2014 December 13, 2014 100 points total Your Instructor and Section I. (10 points, 1 point each) Match each of the terms on the left by choosing the upper case letter of
More informationJava Basic Programming Constructs
Java Basic Programming Constructs /* * This is your first java program. */ class HelloWorld{ public static void main(string[] args){ System.out.println( Hello World! ); A Closer Look at HelloWorld 2 This
More informationKey Java Simple Data Types
AP CS P w Java Unit 1 Multiple Choice Practice Key Java Simple Data Types This test includes program segments, which are not complete programs. Answer such questions with the assumption that the program
More informationJava provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:
JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators
More informationJava Simple Data Types
Intro to Java Unit 1 Multiple Choice Java Simple Data Types DO NOT WRITE ON THIS TEST This test includes program segments, which are not complete programs. Answer such questions with the assumption that
More informationIntroduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017
Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor Sep 2017 Lecture 03: Control Flow Statements: Selection Instructor: AbuKhleif, Mohammad Noor Sep 2017 Instructor AbuKhleif, Mohammad Noor
More informationCIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION
CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1 Name SOLUTION Page Points Score 2 15 3 8 4 18 5 10 6 7 7 7 8 14 9 11 10 10 Total 100 1 P age 1. Program Traces (41 points, 50 minutes)
More informationCS 101 Exam 2 Spring Id Name
CS 101 Exam 2 Spring 2005 Email Id Name This exam is open text book and closed notes. Different questions have different points associated with them. Because your goal is to maximize your number of points,
More information/* Solve f(x) = x*x*x-5 = 0 f'(x) = 3x^2 */
cuberoot /* Solve f(x) = x*x*x-5 = 0 f'(x) = 3x^2 */ public class cuberoot{ public static void main(string args[]){ double error=0.000001; double x0 = 3.0; double c = 5.0; double x1 = x0 - (x0 * x0 * x0
More information1. Short circuit AND (&&) = if first condition is false then the second is never evaluated
1. What are the 2 types of short circuit operators. 1. Short circuit AND (&&) = if first condition is false then the second is never evaluated because true and false gives you false only. 2. Short circuit
More informationCompSci 125 Lecture 11
CompSci 125 Lecture 11 switch case The? conditional operator do while for Announcements hw5 Due 10/4 p2 Due 10/5 switch case! The switch case Statement Consider a simple four-function calculator 16 buttons:
More informationCMPS 12A - Winter 2002 Midterm 2 March 5, Name: ID:
CMPS 12A - Winter 2002 Midterm 2 March 5, 2002 Name: ID: This is a closed note, closed book exam. Any place where you are asked to write code, you must declare all variables that you use. However, I just
More informationEng. Mohammed S. Abdualal
Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 3 Selections
More informationTutorial 06. Conditional statement: if then, if else, switch
College of Computer and Infmation Sciences CSC111 Computer Programming I Exercise 1: Tutial 06 Conditional statement: if then, if, switch What is the output of each of the following code fragments? (given
More informationJAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods
Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn to define and invoke void and return java methods JAVA
More informationFor that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances.
Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose, java provides control structures
More informationCMP 326 Midterm Fall 2015
CMP 326 Midterm Fall 2015 Name: 1) (30 points; 5 points each) Write the output of each piece of code. If the code gives an error, write any output that would happen before the error, and then write ERROR.
More informationPROGRAM: import java.util.scanner;
1. import java.util.scanner; public class printname public static void main(string[] args) System.out.println("Input Your Name:"); String name = new Scanner(System.in).nextLine(); System.out.println("My
More informationCSC 240 Computer Science III Spring 2018 Midterm Exam. Name
CSC 240 Computer Science III Spring 2018 Midterm Exam Name Page Points Score 2 9 4-6 53 7-10 38 Total 100 1 P age 1. Tracing programs (1 point each value): For each snippet of Java code on the left, write
More informationDM550 / DM857 Introduction to Programming. Peter Schneider-Kamp
DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ CALLING & DEFINING FUNCTIONS 2 Functions and
More informationDecision making with if Statement : - Control Statements. Introduction: -
Control Statements Introduction: - Any C program if you consider, the set of statements are normally executed sequentially in the order in which they are written, and such programs have sequential structure
More informationSection 003 Fall CS 170 Exam 2. Name (print): Instructions:
CS 170 Exam 2 Section 003 Fall 2012 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than
More informationYou must declare all variables before they can be used. Following is the basic form of a variable declaration:
Variable Types A variable provides us with named storage that our programs can manipulate. Each variable in Java has a specific type, which determines the size and layout of the variable's memory; the
More informationZheng-Liang Lu Java Programming 45 / 79
1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius
More informationCS180. Exam 1 Review
CS180 Exam 1 Review What is the output to the following code? System.out.println("2 + 2 = " + (2 + 2)); System.out.println("2 + 2 = " + 2 + 2); What is the output to the following code? System.out.println(String.valueOf(15+20));
More informationd. If a is false and b is false then the output is "ELSE" Answer?
Intermediate Level 1) Predict the output for the below code: public void foo( boolean a, boolean b) if( a ) System.out.println("A"); if(a && b) System.out.println( "A && B"); if (!b ) System.out.println(
More informationMore Java Basics. class Vector { Object[] myarray;... //insert x in the array void insert(object x) {...} Then we can use Vector to hold any objects.
More Java Basics 1. INHERITANCE AND DYNAMIC TYPE-CASTING Java performs automatic type conversion from a sub-type to a super-type. That is, if a method requires a parameter of type A, we can call the method
More informationCIS October 16, 2018
CIS 1068 October 16, 2018 administrative stuff @@@ ADD ME @@@ Midterm Remember, the material is cumulative You ll see this stuff again Legal Identifiers c00lg33k is a legal identifier Legal Identifiers
More informationCSE 142, Spring 2009, Sample Final Exam #2. Good luck!
CSE 142, Spring 2009, Sample Final Exam #2 Name: Section: Student ID #: TA: Rules: You have 110 minutes to complete this exam. You will receive a deduction if you keep working after the instructor calls
More informationWentworth Institute of Technology. Engineering & Technology WIT COMP1000. Simple Control Flow: if-else statements
WIT COMP1000 Simple Control Flow: if-else statements Control Flow Control flow is the order in which program statements are executed So far, all of our programs have been executed straight-through from
More informationMotivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018
Motivating Examples (1.1) Selections EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG 1 import java.util.scanner; 2 public class ComputeArea { 3 public static void main(string[] args)
More informationCS 101 Fall 2005 Midterm 2 Name: ID:
This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts (in particular, the final two questions are worth substantially more than any
More informationI pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.
Name: Covers Chapters 1-3 50 mins CSCI 1301 Introduction to Programming Armstrong Atlantic State University Instructor: Dr. Y. Daniel Liang I pledge by honor that I will not discuss this exam with anyone
More informationRoll Number. Common to II Year B.E.CSE & EIE INTERNAL ASSESSMENT TEST - I. Credit 3 R-2017
Roll Number ERODE SENGTHAR ENGINEERING COLLEGE PERDURI, ERODE 638 057 (Accredited by NBA, Accredited by NAAC with A grade, Accredited by IE (I), Kolkotta, Permanently affiliated to Anna University, Chennai
More informationSelections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG
Selections EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG Learning Outcomes The Boolean Data Type if Statement Compound vs. Primitive Statement Common Errors
More informationScheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C
Sample Test Paper-I Marks : 25 Time:1 Hrs. Q1. Attempt any THREE 09 Marks a) State four relational operators with meaning. b) State the use of break statement. c) What is constant? Give any two examples.
More informationGuru Gobind Singh Public School Sector V,B Bokaro Steel City Annual IP Assignment Class 11
Guru Gobind Singh Public School Sector V,B Bokaro Steel City Annual IP Assignment Class 11 1. What will be the output of given expression : int a=7; System.out.println(++a + + a-- + + a+1 + +a++); System.out.println(a);
More informationBuilding Java Programs
Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading: 2.1-2.2 1 2 Data and expressions reading: 2.1 3 The computer s view Internally, computers store everything as 1 s and 0
More informationIntroduction to Computer Science, Shimon Schocken, IDC Herzliya. Lectures Control Structures
Introduction to Computer Science, Shimon Schocken, IDC Herzliya Lectures 3.1 3.2 Control Structures Control Structures, Shimon Schocken IDC Herzliya, www.intro2cs.com slide 1 Control structures A program
More informationKing Saud University College of Computer and Information Sciences Computer Science Department
King Saud University College of Computer and Information Sciences Computer Science Department Course Code: CSC 111 Course Title: Introduction to Programming Semester: Fall 2017-2018 Exercises Cover Sheet:
More informationLoops. CSE 114, Computer Science 1 Stony Brook University
Loops CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation Suppose that you need to print a string (e.g., "Welcome to Java!") a user-defined times N: N?
More informationFor that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances.
Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose, java provides control structures
More informationRepetition, Looping. While Loop
Repetition, Looping Last time we looked at how to use if-then statements to control the flow of a program. In this section we will look at different ways to repeat blocks of statements. Such repetitions
More informationBuilding Java Programs
Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading: 2.1-2.2 1 Data and expressions reading: 2.1 self-check: 1-4 videos: Ch. 2 #1 2 Data types type: A category or set of data
More informationOutline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors
Outline Overview history and advantage how to: program, compile and execute 8 data types 3 types of errors Control statements Selection and repetition statements Classes and methods methods... 2 Oak A
More informationCS 231 Data Structures and Algorithms Fall Event Based Programming Lecture 06 - September 17, Prof. Zadia Codabux
CS 231 Data Structures and Algorithms Fall 2018 Event Based Programming Lecture 06 - September 17, 2018 Prof. Zadia Codabux 1 Agenda Event-based Programming Misc. Java Operator Precedence Java Formatting
More informationCS212 Midterm. 1. Read the following code fragments and answer the questions.
CS1 Midterm 1. Read the following code fragments and answer the questions. (a) public void displayabsx(int x) { if (x > 0) { System.out.println(x); return; else { System.out.println(-x); return; System.out.println("Done");
More informationCIS October 19, 2017
CIS 1068 October 19, 2017 Administrative Stuff String methods due tomorrow Boston Accent Reading: up to chapter 5 Midterms Last Time midterm discussion guessing game Legal Identifiers Ch33zyHaX0R cous
More informationDM503 Programming B. Peter Schneider-Kamp.
DM503 Programming B Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm503/! VARIABLES, EXPRESSIONS & STATEMENTS 2 Values and Types Values = basic data objects 42 23.0 "Hello!" Types
More informationCSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013
CSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013 Name: Section: TA: Student ID #: You have 60 minutes to complete this exam. You may receive a deduction if you keep working after the instructor
More informationBuilding Java Programs
Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading: 2.1-2.2 Copyright 2009 by Pearson Education Data and expressions reading: 2.1 self-check: 1-4 videos: Ch. 2 #1 Copyright
More informationKing Saud University College of Computer and Information Systems Department of Computer Science CSC 113: Java Programming-II, Spring 2016
Create the classes along with the functionality given in the following UML Diagram. To understand the problem, please refer to the description given after the diagram. Node +Node(e:Employee) +getdata():employee
More informationJava Identifiers, Data Types & Variables
Java Identifiers, Data Types & Variables 1. Java Identifiers: Identifiers are name given to a class, variable or a method. public class TestingShastra { //TestingShastra is an identifier for class char
More informationSome Practice Midterm Problems
Some Practice Midterm Problems September 29, 2017 1. 1 point word count is a legal identifier in Java A. True B. False 2. 1 point k2 is a legal identifier in Java A. True B. False 3. 1 point Krazy1 is
More informationFaculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination
First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination Monday, March 9, 2009 Examiners: Mathieu Petitpas [Section 1] 18:30
More information16. Give a detailed algorithm for making a peanut butter and jelly sandwich.
COSC120FinalExamReview2010 1. NamethetwotheoreticalmachinesthatCharlesBabbagedeveloped. 2. WhatwastheAntikytheraDevice? 3. Givethecodetodeclareanintegervariablecalledxandthenassignitthe number10. 4. Givethecodetoprintout
More informationBuilding Java Programs
Building Java Programs Chapter 4 Lecture 4-1: if and if/else Statements reading: 4.2 self-check: #4-5, 7, 10, 11 exercises: #7 videos: Ch. 4 #2-4 The if/else statement Executes one block if a test is true,
More informationSelections. CSE 114, Computer Science 1 Stony Brook University
Selections CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation If you assigned a negative value for radius in ComputeArea.java, then you don't want the
More information1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003
1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 7, 2003 Name: Email Address: TA: Section: You have 90 minutes to complete this exam. For coding questions, you do not need to
More informationUniversity of Massachusetts Amherst, Electrical and Computer Engineering
University of Massachusetts Amherst, Electrical and Computer Engineering ECE 122 Midterm Exam 1 Makeup Answer key March 2, 2018 Instructions: Closed book, Calculators allowed; Duration:120 minutes; Write
More informationCT 229 Java Syntax Continued
CT 229 Java Syntax Continued 06/10/2006 CT229 Lab Assignments Due Date for current lab assignment : Oct 8 th Before submission make sure that the name of each.java file matches the name given in the assignment
More informationJava Review. Java Program Structure // comments about the class public class MyProgram { Variables
Java Program Structure // comments about the class public class MyProgram { Java Review class header class body Comments can be placed almost anywhere This class is written in a file named: MyProgram.java
More informationCMBUkTI4 XøaepÞógpÞat;lkçx½NÐ 3
JAVA Programming - 33 - ChapterIV CMBUkTI4 XøaepÞógpÞat;lkçx½NÐ 3 XøaepÞógpÞat;lkçx½NÐenAkñúgPasa Java RtUv)anerobdak;eTAtamRbePTdUcCa³ Selection, Iteration nig Jump. XøaRbePT Selection GaceGaykmμviFIrbs;eyIgeRCIsyknUvtMeNIrRbtibtþikarepSgKña
More informationSelec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal
Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program
More informationCIS November 14, 2017
CIS 1068 November 14, 2017 Administrative Stuff Netflix Challenge New assignment posted soon Lab grades Last Time. Building Our Own Classes Why Abstraction More on the new operator Fields Class vs the
More informationCSE 142, Summer 2014
CSE 142, Summer 2014 Lecture 2: Static Methods Expressions reading: 1.4 2.1 Algorithms algorithm: A list of steps for solving a problem. Example algorithm: "Bake sugar cookies" Mix the dry ingredients.
More informationCIS March 1, 2018
CIS 1068 March 1, 2018 Administrative Stuff Assignment 6 Today s office hours rescheduled: 12:30-1:50 or appointment, or drop by Last Time more on JUnit and what should be done in Assignment 6 Random sentinel
More informationFull file at
Chapter 3 Flow of Control Multiple Choice 1) An if selection statement executes if and only if: (a) the Boolean condition evaluates to false. (b) the Boolean condition evaluates to true. (c) the Boolean
More information2. What are the two main components to the CPU and what do each of them do? 3. What is the difference between a compiler and an interpreter?
COSC 117 Exam 1 Key Spring 2011 Part 1: Definitions & Short Answer 1. What do CPU and ALU stand for? CPU Central Processing Unit ALU Arithmetic and Logic Unit 2. What are the two main components to the
More informationInterpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled
Interpreted vs Compiled Python 1 Java Interpreted Easy to run and test Quicker prototyping Program runs slower Compiled Execution time faster Virtual Machine compiled code portable Java Compile > javac
More informationMidterm Examination (MTA)
M105: Introduction to Programming with Java Midterm Examination (MTA) Spring 2013 / 2014 Question One: [6 marks] Choose the correct answer and write it on the external answer booklet. 1. Compilers and
More informationCOMP-202: Foundations of Programming. Lecture 10: Method Overloading and Passing Objects to Methods. Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 10: Method Overloading and Passing Objects to Methods. Sandeep Manjanna, Summer 2015 Announcements Assignment 3: Due on 14 th of June at 11:30 pm. Midterm grades
More informationI. True/False: (2 points each)
CS 102 - Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2004 What is your name?: (0 points) There are two sections: I. True/False..............52 points; ( 26 questions, 2 points each) II.
More informationQuestion: Total Points: Score:
CS 170 Exam 1 Section 001 Fall 2014 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than
More informationData Types. 1 You cannot change the type of the variable after declaration. Zheng-Liang Lu Java Programming 52 / 87
Data Types Java is a strongly-typed 1 programming language. Every variable has a type. Also, every (mathematical) expression has a type. There are two categories of data types: primitive data types, and
More informationDM550 Introduction to Programming part 2. Jan Baumbach.
DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net VARIABLES, EXPRESSIONS & STATEMENTS 2 Values and Types Values = basic data objects 42 23.0 "Hello!"
More informationCSC240 Static method, array, and loop.
CSC240 Static method, array, and loop. 1. Tracing programs Code public class Quiz1 public static void main(string [] args) String x = mystery("00"); public static String mystery(string s) s = s + "7";
More informationTop-down programming design
1 Top-down programming design Top-down design is a programming style, the mainstay of traditional procedural languages, in which design begins by specifying complex pieces and then dividing them into successively
More informationBasic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java
Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs, and Java Chapter 2 Primitive Data Types and Operations Chapter 3 Selection
More informationFull file at https://fratstock.eu
Exercise Solutions for Data Structures Using Java Chapter 1 1. a. true; b. false; c. false; d. false; e. false; f. true; g. false; h. false 2. Precondition: The value of x must be nonnegative. Postcondition:
More information