This explanations are for absolute beginners. Skilled programmers should (and probably will) use more effective approach.
|
|
|
- Kevin Evans
- 9 years ago
- Views:
Transcription
1 JAVA EXAMPLES REMARK It turned out that all Workstation in the classroom are NOT set equally. This is why I wil demonstrate all examples using an on-line web tool and/or Please consider using this tool as an alternative to your NetBeans. GENERAL This explanations are for absolute beginners. Skilled programmers should (and probably will) use more effective approach. EXAMPLE 1 ACCOUNT TASK Imagine you have $ on your account. Your bank credits 4% interest for you and you pay maintenance fee $5 monthly. What will be your amount at the end of 5th year? THOUGHTS Imagine how you would do it manually, i.e. with paper, pen and calculator. To calculate amount at the end of the 1 st year, you will take the original amount, increase it by 4% (interests) and decrease by 12(months) * $5 (monthly fee). To calculate amount at the end of the 2nd year, it will be very similar. You will take the amount from the end of 1 st year, increase it by 4% (interests) and decrease by 12(months) * $5 (monthly fee). To calculate amount at the end of the 3rd year, it will be very similar. You will take the amount from the end of 2nd year, increase it by 4% (interests) and decrease by 12(months) * $5 (monthly fee). And so on. You see, that you have a block of computations, that repeats for every year. So you will create a loop that loops 5-times to calculate 5 years and inside the loop will be your every-year-calculation. public class Test { public static void main(string args[]) { double amount = ;
2 /* amount MUST be double, because we will add very small parts (interests) to it */ double interests = 0.04; /* interests must be double. Remember you cannot write 4%, because in JAVA character % has a special meaning. */ double fee = 50; /* It is not necessary to use double for monthly fee; we could use int as well. But double is better, because in the future we may need fees like decimal number. */ int no_years = 5; /* number of years to calculate */ /* now, we will create the loop. We can use for loop here. To pass the loop several times, we need a special variable, pass counter. We can name it current_year, because in fact it describes for which year we do the calculation. Variable current_year will be int, as we do not expect fraction of the year. It is not necessary to initialize current_year, it will be initialized later */ int current_year; for (current_year = 1; current_year<=no_years; current_year++) /* program will loop from year 1 to year 5 inclusive; after each pass the current_year increases by one */ { /* calculating new amount from the old one */ amount = amount + (amount * interests) - (12.0 * fee); /* print the results */ System.out.print("At the end of " + current_year ); System.out.println("th year, amount is " + amount ); ; RESULTS At the end of 1th year, amount is At the end of 2th year, amount is At the end of 3th year, amount is At the end of 4th year, amount is At the end of 5th year, amount is EXAMPLE 2 LOANS TASK
3 You took a loan of $10,000 with interests 12% p.a. and with $75 monthly fee. You pay $3000 pro year. How many years you need to pay the loan? THOUGHTS This is a task very similar to Example 1. But there still is a difference: you do not know number of years. So you cannot use condition current_year<=no_years. Instead, you must loop until you paid, i.e. till your loan is greater than zero. For this case you alternatively can use while loop. To calculate loan at the end of the 1 st year, you will take the original loan, increase it by 12% (interests) and decrease by 12(months) * $75 (monthly fee). public class Test { public static void main(string args[]) { double loan = 10000; /* loan MUST be double, because we will add very small parts (interests) to it */ double interests = 0.12; /* interests must be double. Remember you cannot write 12%, because in JAVA character % has a special meaning. */ double fee = 75; /* It is not necessary to use double for monthly fee; we could use int as well. But double is better, because in the future we may need fees like decimal number. */ double payment = 3000; /* your payment at the end of every year */ int no_years; /* our result: number of years to pay */ /* now, we will create the loop. We can use for loop here. To pass the loop several times, we need a special variable, pass counter. We can name it current_year, because in fact it describes for which year we do the calculation. Variable current_year will be int, as we do not expect fraction of the year. It is not necessary to initialize current_year, it will be initialized later */ int current_year; for (current_year = 1; loan>=0; current_year++) /* program will loop from year 1 till the loan is paid; after each pass the current_year increases by one */ { /* calculating new loan from the old one */ loan = loan + (loan * interests) + (12.0 * fee);
4 loan = loan - payment; /* print the results */ System.out.print("At the end of " + current_year ); System.out.println("th year, loan is " + loan ); ; RESULTS At the end of 1th year, loan is At the end of 2th year, loan is At the end of 3th year, loan is At the end of 4th year, loan is At the end of 5th year, loan is At the end of 6th year, loan is At the end of 7th year, loan is At the end of 8th year, loan is You can see that your loan is fully paid during 8th year. EXAMPLE 3 MONTHLY PAYMENT TASK You took a loan of $10,000 with interests 12% p.a. and with $75 monthly fee. You pay $250 pro year. How many months you need to pay the loan? All calculations will be done monthly THOUGHTS This is a task very similar to Example 2. The only difference is that all calculations take place on the end of month instead of the year. public class Test { public static void main(string args[]) { double loan = 10000; /* loan MUST be double, because we will add very small parts (interests) to it */ double interests = 0.12; /* interests must be double. Remember you cannot write 12%, because in JAVA character % has a special meaning. */ double fee = 75;
5 /* It is not necessary to use double for monthly fee; we could use int as well. But double is better, because in the future we may need fees like decimal number. */ double payment = 250; /* your payment at the end of every month */ int no_months; /* our result: number of months to pay */ /* now, we will create the loop. We can use for loop here. To pass the loop several times, we need a special variable, pass counter. We can name it current_month, because in fact it describes for which month we do the calculation. Variable current_month will be int, as we do not expect fraction of the month. It is not necessary to initialize current_month, it will be initialized later */ int current_month; for (current_month = 1; loan>=0; current_month++) /* program will loop from month 1 till the loan is paid; after each pass the current_month increases by one */ { /* calculating new loan from the old one p.a. interests are divided into 12 months */ loan = loan + (loan * interests/12) + fee; loan = loan - payment; /* print the results - shortened */ if (loan<2000) { System.out.print("At the end of " + current_month ); System.out.println("th month, loan is " + loan ); ; RESULTS At the end of 73th month, loan is At the end of 74th month, loan is At the end of 75th month, loan is At the end of 76th month, loan is At the end of 77th month, loan is At the end of 78th month, loan is At the end of 79th month, loan is At the end of 80th month, loan is At the end of 81th month, loan is At the end of 82th month, loan is At the end of 83th month, loan is
6 At the end of 84th month, loan is At the end of 85th month, loan is At the end of 86th month, loan is You can see that your loan is fully paid during 86th month. Also, you can see that after 84 th month, i.e. after 7 th year, your loan still is , while in example 2 (yearly calculating) is fully paid. Results that monthly calculating is better for banks ( and this is why it is used by banks). EXAMPLE Compute area and perimeter of a circle, r = 25. public class Pi0{ public static void main(string []args){ double pi = ; double r = 25.0; double perimeter = 2*pi*r; double area = pi*r*r; System.out.println("area=" + area); System.out.println("perimeter=" + perimeter); EXAMPLE: SIMPLE INPUT/OUTPUT this example was deleted: sorry for discomfort EXAMPLE: LUDOLF S NUMBER Π (1) Compute Ludolf s number π as a sum of infinite queue, using formula: Pi = 4*( 1-1/3 + 1/5-1/7 + 1/9-1/ ) public class Pi1{ public static void main(string []args){ int sig = 1; double pi = 0.0; double denom = 1.0;
7 int n = 1; do { System.out.print("pass n= "+n); pi = pi + sig/denom; System.out.println(", pi= " + pi); sig = -sig; denom = denom + 2; n++; while (denom < 10); pi = 4*pi; System.out.print("Result: Pi = " + pi); RESULT Result, after 5 passes, is: pass n= 1, pi= 1.0 pass n= 2, pi= pass n= 3, pi= pass n= 4, pi= pass n= 5, pi= Result: Pi = EXAMPLE: LUDOLF S NUMBER Π (2) Compute Ludolf s number π as a sum of infinite queue, using formula: Pi = 4*( (1/2+1/3) - (1/2^3+1/3^3)/3 + (1/2^5+1/3^5)/5 - (1/2^7+1/3^7)/ ) GUIDE Theoretically, we can evaluate the expression in a loop, again and again. Unfortunately, computing high powers of 2 and 3 is too time-consuming. This is why, in practice, consider to compute the new expression for n=n+1 using old resulrs for n. When going from n n+1 we obtain: and
8 This will be used for computation. We will define a variable clen2 (i.e. fraction with power of 2 in its denominator) and clen3 (fraction with power of 3 in its denominator). During each cycle we will divide it by 4 or 9 respectively.
Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:
In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our
CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius
Programming Concepts Practice Test 1 1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius 2) Consider the following statement: System.out.println("1
J a v a Quiz (Unit 3, Test 0 Practice)
Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points
System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :
Benjamin Michael Java Homework 3 10/31/2012 1) Sales.java Code // Sales.java // Program calculates sales, based on an input of product // number and quantity sold import java.util.scanner; public class
Part I. Multiple Choice Questions (2 points each):
Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******
Using Two-Dimensional Arrays
Using Two-Dimensional Arrays Great news! What used to be the old one-floor Java Motel has just been renovated! The new, five-floor Java Hotel features a free continental breakfast and, at absolutely no
You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:
Lecture 7 Picking Balls From an Urn The problem: An urn has n (n = 10) balls numbered from 0 to 9 A ball is selected at random, its' is number noted, it is set aside, and another ball is selected from
Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language
Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description
Contents. 9-1 Copyright (c) 1999-2004 N. Afshartous
Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10. Introduction to
The following program is aiming to extract from a simple text file an analysis of the content such as:
Text Analyser Aim The following program is aiming to extract from a simple text file an analysis of the content such as: Number of printable characters Number of white spaces Number of vowels Number of
IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).
IRA EXAMPLES This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account). Definite Counting Loop Example IRA After x Years This first example illustrates
Building Java Programs
Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print
Sample CSE8A midterm Multiple Choice (circle one)
Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names
Building Java Programs
Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print
JAVA ARRAY EXAMPLE PDF
JAVA ARRAY EXAMPLE PDF Created By: Umar Farooque Khan 1 Java array example for interview pdf Program No: 01 Print Java Array Example using for loop package ptutorial; public class PrintArray { public static
LOOPS CHAPTER CHAPTER GOALS
jfe_ch04_7.fm Page 139 Friday, May 8, 2009 2:45 PM LOOPS CHAPTER 4 CHAPTER GOALS To learn about while, for, and do loops To become familiar with common loop algorithms To understand nested loops To implement
Programmierpraktikum
Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 21 10/16/2012 09:29 AM Java - A First Glance 2 of 21 10/16/2012 09:29 AM programming languages
File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)
File class in Java File Input and Output (Savitch, Chapter 10) TOPICS File Input Exception Handling File Output Programmers refer to input/output as "I/O". The File class represents files as objects. The
Building Java Programs
Building Java Programs Chapter 5 Lecture 5-2: Random Numbers reading: 5.1-5.2 self-check: #8-17 exercises: #3-6, 10, 12 videos: Ch. 5 #1-2 1 The Random class A Random object generates pseudo-random* numbers.
Introduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
In this Chapter you ll learn:
Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then stop. Lewis
This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output: 1 2 3 4 5 6 7 8 9 10
Java Loops & Methods The while loop Syntax: while ( condition is true ) { do these statements Just as it says, the statements execute while the condition is true. Once the condition becomes false, execution
How do you compare numbers? On a number line, larger numbers are to the right and smaller numbers are to the left.
The verbal answers to all of the following questions should be memorized before completion of pre-algebra. Answers that are not memorized will hinder your ability to succeed in algebra 1. Number Basics
Decimals are absolutely amazing We have only 10 symbols, yet can represent any number, large or small We use zero (0) as a place holder to allow us
Decimals 1 Decimals are absolutely amazing We have only 10 symbols, yet can represent any number, large or small We use zero (0) as a place holder to allow us to do this 2 Some Older Number Systems 3 Can
Chapter 3. Input and output. 3.1 The System class
Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use
Using Files as Input/Output in Java 5.0 Applications
Using Files as Input/Output in Java 5.0 Applications The goal of this module is to present enough information about files to allow you to write applications in Java that fetch their input from a file instead
Comp 248 Introduction to Programming
Comp 248 Introduction to Programming Chapter 2 - Console Input & Output Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal, Canada These slides has been
Java CPD (I) Frans Coenen Department of Computer Science
Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials
JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4
JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 NOTE: SUN ONE Studio is almost identical with NetBeans. NetBeans is open source and can be downloaded from www.netbeans.org. I
Collections.sort(population); // Método de ordenamiento
import java.util.collections; import java.util.linkedlist; import java.util.random; public class GeneticAlgorithms static long BEGIN; static final boolean _DEBUG = true; LinkedList population
(Eng. Hayam Reda Seireg) Sheet Java
(Eng. Hayam Reda Seireg) Sheet Java 1. Write a program to compute the area and circumference of a rectangle 3 inche wide by 5 inches long. What changes must be made to the program so it works for a rectangle
CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java
CS1020 Data Structures and Algorithms I Lecture Note #1 Introduction to Java Objectives Java Basic Java features C Java Translate C programs in CS1010 into Java programs 2 References Chapter 1 Section
Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output
Chapter 2 Console Input and Output System.out.println for console output System.out is an object that is part of the Java language println is a method invoked dby the System.out object that can be used
Manual For Using the NetBeans IDE
1 Manual For Using the NetBeans IDE The content of this document is designed to help you to understand and to use the NetBeans IDE for your Java programming assignments. This is only an introductory presentation,
Introduction to Object-Oriented Programming
Introduction to Object-Oriented Programming Programs and Methods Christopher Simpkins [email protected] CS 1331 (Georgia Tech) Programs and Methods 1 / 8 The Anatomy of a Java Program It is customary
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard
INPUT & OUTPUT I/O Example Using keyboard input for characters import java.util.scanner; class Echo{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); // scanner for the keyboard
CAHSEE on Target UC Davis, School and University Partnerships
UC Davis, School and University Partnerships CAHSEE on Target Mathematics Curriculum Published by The University of California, Davis, School/University Partnerships Program 006 Director Sarah R. Martinez,
$496. 80. Example If you can earn 6% interest, what lump sum must be deposited now so that its value will be $3500 after 9 months?
Simple Interest, Compound Interest, and Effective Yield Simple Interest The formula that gives the amount of simple interest (also known as add-on interest) owed on a Principal P (also known as present
Chapter 4 -- Decimals
Chapter 4 -- Decimals $34.99 decimal notation ex. The cost of an object. ex. The balance of your bank account ex The amount owed ex. The tax on a purchase. Just like Whole Numbers Place Value - 1.23456789
Math 0306 Final Exam Review
Math 006 Final Exam Review Problem Section Answers Whole Numbers 1. According to the 1990 census, the population of Nebraska is 1,8,8, the population of Nevada is 1,01,8, the population of New Hampshire
Chapter 2 Introduction to Java programming
Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break
MTH6120 Further Topics in Mathematical Finance Lesson 2
MTH6120 Further Topics in Mathematical Finance Lesson 2 Contents 1.2.3 Non-constant interest rates....................... 15 1.3 Arbitrage and Black-Scholes Theory....................... 16 1.3.1 Informal
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java
AP Computer Science Static Methods, Strings, User Input
AP Computer Science Static Methods, Strings, User Input Static Methods The Math class contains a special type of methods, called static methods. A static method DOES NOT operate on an object. This is because
Arrays in Java. Working with Arrays
Arrays in Java So far we have talked about variables as a storage location for a single value of a particular data type. We can also define a variable in such a way that it can store multiple values. Such
13 File Output and Input
SCIENTIFIC PROGRAMMING -1 13 File Output and Input 13.1 Introduction To make programs really useful we have to be able to input and output data in large machinereadable amounts, in particular we have to
Building Java Programs
Building Java Programs Chapter 4 Lecture 4-1: Scanner; if/else reading: 3.3 3.4, 4.1 Interactive Programs with Scanner reading: 3.3-3.4 1 Interactive programs We have written programs that print console
Area, Perimeter, Volume and Pythagorean Theorem Assessment
Area, Perimeter, Volume and Pythagorean Theorem Assessment Name: 1. Find the perimeter of a right triangle with legs measuring 10 inches and 24 inches a. 34 inches b. 60 inches c. 120 inches d. 240 inches
Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.
Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input
Future Value of an Annuity Sinking Fund. MATH 1003 Calculus and Linear Algebra (Lecture 3)
MATH 1003 Calculus and Linear Algebra (Lecture 3) Future Value of an Annuity Definition An annuity is a sequence of equal periodic payments. We call it an ordinary annuity if the payments are made at the
Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013
Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper
Data Structures Lecture 1
Fall 2015 Fang Yu Software Security Lab. Dept. Management Information Systems, National Chengchi University Data Structures Lecture 1 A brief review of Java programming Popularity of Programming Languages
Classes: Relationships Among Objects. Atul Prakash Background readings: Chapters 8-11 (Downey)
Classes: Relationships Among Objects Atul Prakash Background readings: Chapters 8-11 (Downey) Real-World Relationships: Parent-child relationships among members of a species Friends relationship among
Topic 11 Scanner object, conditional execution
Topic 11 Scanner object, conditional execution "There are only two kinds of programming languages: those people always [complain] about and those nobody uses." Bjarne Stroustroup, creator of C++ Copyright
Postulate 17 The area of a square is the square of the length of a. Postulate 18 If two figures are congruent, then they have the same.
Chapter 11: Areas of Plane Figures (page 422) 11-1: Areas of Rectangles (page 423) Rectangle Rectangular Region Area is measured in units. Postulate 17 The area of a square is the square of the length
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui
TCP/IP Drill Pack. By Donna Warren. Created by Donna P. Warren Revised: 1/2/2012 Page 1 of 19
TCP/IP Drill Pack By Donna Warren Created by Donna P. Warren Revised: 1/2/2012 Page 1 of 19 Drill 1: OSI vs DOD and the TCP/IP Protocol Suite Complete the following chart. On the next page give a brief
Homework 2 Solutions
Homework Solutions 1. (a) Find the area of a regular heagon inscribed in a circle of radius 1. Then, find the area of a regular heagon circumscribed about a circle of radius 1. Use these calculations to
1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders
1.00 Lecture 1 Course Overview Introduction to Java Reading for next time: Big Java: 1.1-1.7 Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders
Object-Oriented Programming in Java
CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio
Unit 6. Loop statements
Unit 6 Loop statements Summary Repetition of statements The while statement Input loop Loop schemes The for statement The do statement Nested loops Flow control statements 6.1 Statements in Java Till now
Java Program Coding Standards 4002-217-9 Programming for Information Technology
Java Program Coding Standards 4002-217-9 Programming for Information Technology Coding Standards: You are expected to follow the standards listed in this document when producing code for this class. Whether
MULTIPLICATION AND DIVISION OF REAL NUMBERS In this section we will complete the study of the four basic operations with real numbers.
1.4 Multiplication and (1-25) 25 In this section Multiplication of Real Numbers Division by Zero helpful hint The product of two numbers with like signs is positive, but the product of three numbers with
5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int.
Java How to Program, 5/e Test Item File 1 of 5 Chapter 5 Section 5.2 5.2 Q1 Counter-controlled repetition requires a.a control variable and initial value. b.a control variable increment (or decrement).
Object Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]
Pre-Algebra Lecture 6
Pre-Algebra Lecture 6 Today we will discuss Decimals and Percentages. Outline: 1. Decimals 2. Ordering Decimals 3. Rounding Decimals 4. Adding and subtracting Decimals 5. Multiplying and Dividing Decimals
Fractions to decimals
Worksheet.4 Fractions and Decimals Section Fractions to decimals The most common method of converting fractions to decimals is to use a calculator. A fraction represents a division so is another way of
Two-Dimensional Arrays. Multi-dimensional Arrays. Two-Dimensional Array Indexing
Multi-dimensional Arrays The elements of an array can be any type Including an array type So int 2D[] []; declares an array of arrays of int Two dimensional arrays are useful for representing tables of
Basics of Java Programming Input and the Scanner class
Basics of Java Programming Input and the Scanner class CSC 1051 Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/
Iteration CHAPTER 6. Topic Summary
CHAPTER 6 Iteration TOPIC OUTLINE 6.1 while Loops 6.2 for Loops 6.3 Nested Loops 6.4 Off-by-1 Errors 6.5 Random Numbers and Simulations 6.6 Loop Invariants (AB only) Topic Summary 6.1 while Loops Many
CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement
CompSci 125 Lecture 08 Chapter 5: Conditional Statements Chapter 4: return Statement Homework Update HW3 Due 9/20 HW4 Due 9/27 Exam-1 10/2 Programming Assignment Update p1: Traffic Applet due Sept 21 (Submit
Java Basics: Data Types, Variables, and Loops
Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables
1 Hour, Closed Notes, Browser open to Java API docs is OK
CSCI 143 Exam 2 Name 1 Hour, Closed Notes, Browser open to Java API docs is OK A. Short Answer For questions 1 5 credit will only be given for a correct answer. Put each answer on the appropriate line.
Linear Equations and Inequalities
Linear Equations and Inequalities Section 1.1 Prof. Wodarz Math 109 - Fall 2008 Contents 1 Linear Equations 2 1.1 Standard Form of a Linear Equation................ 2 1.2 Solving Linear Equations......................
Example of a Java program
Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);
How to create/avoid memory leak in Java and.net? Venkat Subramaniam [email protected] http://www.durasoftcorp.com
How to create/avoid memory leak in Java and.net? Venkat Subramaniam [email protected] http://www.durasoftcorp.com Abstract Java and.net provide run time environment for managed code, and Automatic
Florida Math 0028. Correlation of the ALEKS course Florida Math 0028 to the Florida Mathematics Competencies - Upper
Florida Math 0028 Correlation of the ALEKS course Florida Math 0028 to the Florida Mathematics Competencies - Upper Exponents & Polynomials MDECU1: Applies the order of operations to evaluate algebraic
Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.
Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6 Handout 3 Strings and String Class. Input/Output with JOptionPane. Strings In Java strings are represented with a class type String. Examples:
7 Literal Equations and
CHAPTER 7 Literal Equations and Inequalities Chapter Outline 7.1 LITERAL EQUATIONS 7.2 INEQUALITIES 7.3 INEQUALITIES USING MULTIPLICATION AND DIVISION 7.4 MULTI-STEP INEQUALITIES 113 7.1. Literal Equations
CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O
CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void
Java Programming Unit 1. Your first Java Program Eclipse IDE
Java Programming Unit 1 Your first Java Program Eclipse IDE During this training course we ll use the textbook Java Programming 24- Hour Trainer by Yakov Fain. Why Learn Java? Large code base of already
AP Computer Science File Input with Scanner
AP Computer Science File Input with Scanner Subset of the Supplement Lesson slides from: Building Java Programs, Chapter 6 by Stuart Reges and Marty Stepp (http://www.buildingjavaprograms.com/ ) Input/output
Percent, Sales Tax, & Discounts
Percent, Sales Tax, & Discounts Many applications involving percent are based on the following formula: Note that of implies multiplication. Suppose that the local sales tax rate is 7.5% and you purchase
THE TIME VALUE OF MONEY
QUANTITATIVE METHODS THE TIME VALUE OF MONEY Reading 5 http://proschool.imsindia.com/ 1 Learning Objective Statements (LOS) a. Interest Rates as Required rate of return, Discount Rate and Opportunity Cost
Lesson Plan. N.RN.3: Use properties of rational and irrational numbers.
N.RN.3: Use properties of rational irrational numbers. N.RN.3: Use Properties of Rational Irrational Numbers Use properties of rational irrational numbers. 3. Explain why the sum or product of two rational
To Evaluate an Algebraic Expression
1.5 Evaluating Algebraic Expressions 1.5 OBJECTIVES 1. Evaluate algebraic expressions given any signed number value for the variables 2. Use a calculator to evaluate algebraic expressions 3. Find the sum
What are the place values to the left of the decimal point and their associated powers of ten?
The verbal answers to all of the following questions should be memorized before completion of algebra. Answers that are not memorized will hinder your ability to succeed in geometry and algebra. (Everything
Chapter 2 Elementary Programming
Chapter 2 Elementary Programming 2.1 Introduction You will learn elementary programming using Java primitive data types and related subjects, such as variables, constants, operators, expressions, and input
Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion 15.3.2014-20.3.2014
German University in Cairo Media Engineering and Technology Prof. Dr. Slim Abdennadher Dr. Ahmed Gamal Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion 15.3.2014-20.3.2014
FRACTIONS OPERATIONS
FRACTIONS OPERATIONS Summary 1. Elements of a fraction... 1. Equivalent fractions... 1. Simplification of a fraction... 4. Rules for adding and subtracting fractions... 5. Multiplication rule for two fractions...
3 length + 23 size = 2
This pledged exam is closed textbook, open class web site, and two pieces of paper with notes. You may not access any other code or websites including your own. Write your email id and name on every page
