(Eng. Hayam Reda Seireg) Sheet Java
|
|
- Teresa Walters
- 8 years ago
- Views:
Transcription
1 (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 6.8 inches wide by 2.3 inches long? public class AreaOfRectangle public static void main(string[] args) int width=3,height=5; // double width=6.8,height=2.3; int area,circumference; // double area,circumference; area = width height; circumference = 2 ( width + height); System.out.println("The area of rectangle is "+ area+" the circumference is "+ circumference); 2- Write a program to print your name, and date of birth? public class YourName public static void main(string[] args) System.out.println("My name is kamal and the date of my birth is 4/9/1984"); 3- Write a program to sum up all the numbers in array? package hayam public class SumOfTheArray 1
2 public static void main(string[] args) int size,sum=0; System.out.println("Enter the size of the array "); size=scan.nextint(); int [] x = new int [size]; for( int i=0;i<size;i++) System.out.println("Enter the array "); x[i] =scan.nextint(); sum = sum +x[i]; System.out.println("The sum of the array is "+ sum); 4- Write a program to multiply two arrays? package hayam public class MultiplyArray public static void main(string[] args) int size,j=0; System.out.println("Enter the size of the array "); size=scan.nextint(); int [] x = new int [ size ]; int [] m = new int [size]; int [] mul = new int [size]; for( int i=0;i<size;i++) 2
3 System.out.println("Enter the array 1"); x[i] =scan.nextint(); System.out.println("Enter the array 2"); m[j] =scan.nextint(); mul[i] = x[i] m[j]; for( int i=0;i<size;i++) System.out.println("The result is "+ mul[i] ); 5- Write a program that converts Celsius to Fahrenheit. package hayam public class Celuus public static void main(string[] args) double c,f; System.out.println("Enter the celsius"); c = scan.nextdouble(); f = (9.0/5.0 c+32); System.out.println("the fahrenheit is " + f ); 3
4 6- Write a program to calculate the volume of a sphere, package hayam public class VolumeOfTheSphere public static void main(string[] args) double radius,volume; System.out.println("Enter the number of the radius "); radius=scan.nextdouble(); volume =((4.0/3.0) Math.PI Math.pow(radius, 3)); System.out.println("volume of the sphere = " + volume ); 7- Write a program to print out the perimeter of a rectangle given its height and width. perimeter = 2 (width+height) package hayam public class PERIMETER 4
5 public static void main(string[] args) // TO CALCULATE THE PERIMETR OF RECTANGLE double width,height,perimeter; width =2.0; height = 3.4; perimeter = 2 (width + height); System.out.println("perimeter =" + perimeter); 8- Write a program that converts kilometers per hour to miles per hour. miles = (kilometers ) package hayam public class KilometersPerHours public static void main(string[] args) 5
6 double kilometers,miles; System.out.println("Enter the value of the kilometers per hours"); kilometers = scan.nextdouble(); miles= (kilometers ); System.out.println("miles per hours"+ miles); 9- Write a program that takes hours and minutes as input and outputs the total number of minutes ( 1 hour 30 minutes = 90 minutes). package hayam public class HoursAndMinutes public static void main(string[] args) int hours,minutes,a=0; 6
7 System.out.println("Enter the hours and minutes"); hours = scan.nextint(); minutes = scan.nextint(); if (minutes>=0 && hours>=0&& hours <= 12 && minutes<=60) for (int i=1;i<=hours;i++) a = a + 60; minutes = minutes + a; System.out.println(minutes + " minutes"); else System.out.println("Error input"); 10- Write a program that takes an integer as the number of minutes and outputs the total hours and minutes (90 minutes = 1 hour 30 minutes). package minutes; 7
8 @author hayam public class MINUTES public static void main(string[] args) int minutes, hours=0,a=60; System.out.println("Enter the minutes "); minutes = scan.nextint(); if (minutes>60 && minutes>=0) for (int i=60;i<=minutes;i=+60) hours = hours + 1; minutes = minutes - a; System.out.println(hours +"hours " + minutes+ " minutes"); else System.out.println(minutes + " minutes"); 8
9 11- Write a program to find the square of the distance between two points. package hayam public class Distance public static void main(string[] args) double p1,p2,q1,q2,distance; System.out.println("Enter the x1 for the first point "); p1 =scan.nextint(); System.out.println("Enter the y1 for the first point "); p2 =scan.nextint(); System.out.println("Enter the x2 for the second point "); q1 =scan.nextint(); System.out.println("Enter the y2 for the second point "); q2 =scan.nextint(); //if p = (p1, p2) and q = (q1, q2) //standard Euclidean distance can be squared in order to place //progressively greater weight on objects that are further apart. In this case, the equation //d(p,q) = (p1 q1)2 + (p2 q2) (pi qi) (pn qn)2. //the program calculate the square between distance between two points distance = (Math.pow((p1-q1),2)+ Math.pow((p2-q2),2)); System.out.println("standard Euclidean distance can be squared is " + distance); 9
10 12- A professor generates letter grades using the following table: Given a numeric grade, print the letter. package hayam public class Degree public static void main(string[] args) System.out.println("Enter the numerica grade "); System.out.println("Please don't enter number greater than 100"); 10
11 int x = scan.nextint(); if(x>100) System.out.println("bad input"); else if ( x>=91 x==100) System.out.println("A"); else if ( x>=81 x==90) System.out.println("B"); else if (x>=71 x==80) System.out.println("C"); else if (x>=61 x==70) System.out.println("D"); else if (x>=0 x==60) System.out.println("F"); 13- Modify the previous program to print out a + or - after the letter grade based on the last digit of the score. The modifiers are listed in the following table For example, 81=B-, 94=A, and 68=D+. Note: n F is only an F. There is no F+ or F-. package grades; 11
12 @author hayam public class Grades public static void main(string[] args) System.out.println("Enter the numeric grades "); int x = scan.nextint(); String astring = Integer.toString(x); if (x>100) System.out.println("error,wrong input"); else if (x >=91 x==100 ) if (astring.charat(1)==56 astring.charat(1)==48 astring.charat(1)==57)// NUMBER 8 IN THE ASCI CODE IS 56 AND NUMBER 0 IN THE ASCI CODE 48 AND NUMBER 9 IN THE ASCI CODE IS 57 System.out.println("A+"); else if (astring.charat(1)==49 astring.charat(1)==51 astring.charat(1)==50) System.out.println("A-"); 12
13 else System.out.println("A"); else if (x>=81 x==90) if (astring.charat(1)==56 astring.charat(1)==48 astring.charat(1)==57) System.out.println("B+"); if (astring.charat(1)==49 astring.charat(1)==51 astring.charat(1)==50) System.out.println("B-"); else System.out.print("B "); else if (x>=71 x==80) if (astring.charat(1)==56 astring.charat(1)==48 astring.charat(1)==57) System.out.println("C+"); else if (astring.charat(1)==49 astring.charat(1)==51 astring.charat(1)==50) System.out.println("C-"); else System.out.println("C"); else if (x>=61 x==70) if (astring.charat(1)==56 astring.charat(1)==48 astring.charat(1)==57) 13
14 System.out.println("D+"); else if (astring.charat(1)==49 astring.charat(1)==51 astring.charat(1)==50) System.out.println("D-"); else System.out.println("D"); else if (x>=0 x==60) System.out.println("F"); 14- Write a program that takes a series of numbers and counts the number of positive and negative values. package hayam public class CountPositive public static void main(string[] args) 14
15 int size, count=0,n=0; System.out.println("Enter the size of the array "); size= scan.nextint(); int [] x = new int [size]; for( int i=0;i<size;i++) System.out.println("Enter the array "); x[i] =scan.nextint(); if ( x[i]> 0) System.out.println("The positive value is " + ++ count); else if (x[i] <0) System.out.println("The negative value is " + ++ n); else if (x[i]==0) System.out.println("The value is zero "); 15- Write a program to average n numbers. package average.number; 15
16 @author hayam public class AVERAGENUMBER public static void main(string[] args) int size; double sum=0,n; double average; System.out.println("Enter the size of the array "); size=scan.nextint(); int [] x = new int [size]; for( int i=0;i < size;i++) System.out.println("Enter the array "); x[i] =scan.nextint(); sum = sum + x[i]; average = sum / size; 16
17 System.out.println(" the average value is "+ average) ; 17- Write a program that converts numbers to words. Example: 895 results in ''eight nine five." package hayam public class OPDF public static void main(string[] args) String in; String [] name= "zero","one","two","three","four","five","six","seven","eight","nine"; System.out.println("Enter the number "); in=scan.next(); for(int i=0;i<in.length();i++) 17
18 if (in.charat(i)>=48 && in.charat(i)<59) System.out.print(name[(in.charAt(i)-48)]+" "); 16- Write a program that reads a character and prints out whether or not it is a vowel or a consonant. package hayam public class Consonant public static void main(string[] args) 18
19 System.out.println("Enter the character"); String x =scan.next(); x= x.touppercase(); if( x.charat(0) =='A' x.charat(0)=='e' x.charat(0)=='i' x.charat(0)== 'O' x.charat(0)=='u' ) System.out.println("vowels"); else System.out.println("cononsant"); 19
20 1. Write a program that declares and initializes an array a[] of size 1000 and accesses a[1000]. Does your program compile? What happens when you run it? int [ ] a = new int [1000]; for(int i=0;i<1000;i++) a[i]=i; int x=a[1000];it is wrong because the program cannot access 1000 so it can access a[999], the program can access from 0 to 999 when you initialized the size of array Given two vectors of length N that are represented with one-dimensional arrays, write a code fragment that computes the Euclidean distance between them (the square root of the sums of the squares of the differences between corresponding entries). package hayam public class Vector public static void main(string[] args) int size; double out,sum=0; 20
21 System.out.println("Enter the size of the array 1"); size=scan.nextint(); int A[]= new int[size]; int B[]= new int[size]; int C[]= new int[size]; int D[]= new int[size]; for(int i=0;i<size;i++) System.out.println("Enter the array of x1"); A[i]=scan.nextInt(); System.out.println("Enter the array of y1"); B[i]=scan.nextInt(); System.out.println("Enter the array of x2"); C[i]=scan.nextInt(); System.out.println("Enter the array of y2"); D[i]=scan.nextInt(); for(int i=0;i<size;i++) sum=(math.pow(c[i]-a[i],2)+math.pow(d[i]-b[i],2)); System.out.println("the result is "+ sum ); out = Math.sqrt(sum); System.out.println("the result is "+ out); 21
22 3. Write a code fragment that reverses the order of a one-dimensional array a[] of double values. Do not create another array to hold the result. Hint: Use the code in the text for exchanging two elements. Solution. int N = a.length; for (int i = 0; i < N/2; i++) double temp = a[n-i-1]; a[n-i-1] = a[i]; a[i] = temp; 4. What is wrong with the following code fragment? int[] a; for (int i = 0; i < 10; i++) a[i] = i i; Solution: It does not allocate memory for a[] with new. The code results in a variable might not have been initialized compile-time error. 5. What does the following code fragment print? int [] a = new int[10]; for (int i = 0; i < 10; i++) a[i] = 9 - i; for (int i = 0; i < 10; i++) a[i] = a[a[i]]; for (int i = 0; i < 10; i++) System.out.println(a[i]); Solution is
23 6. What values does the following code put in the array a? N = 10; int[] a = new int[n]; a[0] = 0; a[1] = 1; for (int i = 0; i < N; i++) a[i] = a[i-1] + a[i-2]; System.out.println(a[i]); Solution : Error, it is out of range of the index (Array Index Out Of Bounds Exception). 7. What does the following code fragment print? int[] a = 1, 2, 3 ; int[] b = 1, 2, 3 ; System.out.println(a == b); Solution: It prints false. The == operator compares whether the (memory addresses of the) two arrays are identical, not whether their corresponding values are equal. 8. Write a program that computes the product of two square matrices of boolean values, using the or operation instead of + and the and operation instead of. package hayam public class OrAndMatrix public static void main(string[] args) Scanner scan = new Scanner(System.in); int i, n, j, k, w,o,f; 23
24 System.out.println("Enter the row of the first matrix"); i = scan.nextint(); System.out.println("Enter the column of the first matrix"); j = scan.nextint(); System.out.println("Enter the row of the second matrix"); k = scan.nextint(); System.out.println("Enter the column of the second matrix"); n = scan.nextint(); int[][] z = new int[i][n]; int[][] x = new int[i][j]; int[][] y = new int[k][n]; if (j == k) for ( o = 0; o < i; o++) for ( f = 0; f < j; f++) System.out.println("Enter the value of the first matrix " + "x[" + o + "][" + f + "]"); x[o][f] = scan.nextint(); for ( o = 0; o < k; o++) for ( f = 0; f < n; f++) System.out.println("Enter the value of the secopnd matrix " + "y[" + o + "][" + f + "]"); y[o][f] = scan.nextint(); 24
25 else System.out.println("Error input"); for (int b = 0; b < i; b++) for (int c = 0; c < n; c++) int sum; if (j >= 3 k >= 3) w = j = k; for (int d = 2; d < w; d++) sum = x[b][d] & y[d][c]; z[b][c] = x[b][0] & y[0][c] x[b][1] & y[1][c] sum; System.out.println("z" + "[" + b + "][" + c + "]" + " = " + z[b][c]); else z[b][c] = x[b][0] & y[0][c] x[b][1] & y[1][c]; System.out.println("z" + "[" + b + "][" + c + "]" + " = " + z[b][c]); 25
26 9. Write a code fragment to multiply two rectangular matrices that are not necessarily square. Note: For the dot product to be well-defined, the number of columns in the first matrix must be equal to the number of rows in the second matrix. Print an error message if the dimensions do not satisfy this condition. package hayam public class Project public static void main(string[] args) int i,n,j,k,w; System.out.println("Enter the row of the first matrix"); i = scan.nextint(); System.out.println("Enter the column of the first matrix"); j = scan.nextint(); System.out.println("Enter the row of the second matrix"); 26
27 k = scan.nextint(); System.out.println("Enter the column of the second matrix"); n = scan.nextint(); int [][] z = new int [i][n]; int [][] x = new int [i][j]; int [][] y = new int [k][n]; if (j==k) for(int o=0;o<i;o++) for(int f=0;f<j;f++) System.out.println("Enter the value of the first matrix "+ "x["+o+"]["+f+"]"); x[o][f]= scan.nextint(); for(int o=0;o<k;o++) for(int f=0;f<n;f++) System.out.println("Enter the value of the secopnd matrix " + "y["+o+"]["+f+"]"); y[o][f]= scan.nextint(); for(int b=0;b<i;b++) 27
28 for(int c=0;c<n;c++) int sum; if (j>=3 k>=3) w=j=k; for(int d=2;d<w;d++) sum=x[b][d]y[d][c]; z[b][c]= x[b][0]y[0][c]+x[b][1]y[1][c]+sum; System.out.println("z"+"["+b+"]["+c+"]"+" = " + z[b][c]); else z[b][c]= x[b][0]y[0][c]+x[b][1]y[1][c]; System.out.println("z"+"["+b+"]["+c+"]"+" = "+ z[b][c]); else System.out.println("Error input"); 28
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
More information1) 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
More informationPart 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 ******
More informationCS 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)
More informationJAVA 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
More informationSystem.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
More informationScanner 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
More informationIntroduction to Java. CS 3: Computer Programming in Java
Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods
More informationFile 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
More informationJ 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
More informationThe 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
More informationTopic 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
More informationArrays 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
More informationCOSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005. Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19
Term Test #2 COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005 Family Name: Given Name(s): Student Number: Question Out of Mark A Total 16 B-1 7 B-2 4 B-3 4 B-4 4 B Total 19 C-1 4
More informationCS114: Introduction to Java
CS114: Introduction to Java Fall 2015, Mon/Wed, 5:30 PM - 6:45 PM Instructor: Pejman Ghorbanzade to Assignment 4 Release Date: Nov 04, 2015 at 5:30 PM Due Date: Nov 18, 2015 at 5:30 PM Question 1 An n
More informationTwo-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
More informationIntroduction 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
More informationCS170 Lab 11 Abstract Data Types & Objects
CS170 Lab 11 Abstract Data Types & Objects Introduction: Abstract Data Type (ADT) An abstract data type is commonly known as a class of objects An abstract data type in a program is used to represent (the
More informationTranslating 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
More informationExample 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]);
More informationMULTIPLE 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
More informationMIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION
MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION 1. Write a loop that computes (No need to write a complete program) 100 1 99 2 98 3 97... 4 3 98 2 99 1 100 Note: this is not the only solution; double sum
More informationYou 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
More informationBasics 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/
More informationJDK 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
More informationClasses 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
More informationSection 6 Spring 2013
Print Your Name You may use one page of hand written notes (both sides) and a dictionary. No i-phones, calculators or any other type of non-organic computer. Do not take this exam if you are sick. Once
More informationExplain the relationship between a class and an object. Which is general and which is specific?
A.1.1 What is the Java Virtual Machine? Is it hardware or software? How does its role differ from that of the Java compiler? The Java Virtual Machine (JVM) is software that simulates the execution of a
More informationBuilding 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
More informationHow 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
More informationFirst 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
More informationInteractive Applications (CLI) and Math
Interactive Applications (CLI) and Math Interactive Applications Command Line Interfaces The Math Class Example: Solving Quadratic Equations Example: Factoring the Solution Reading for this class: L&L,
More informationCompSci 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
More informationCS1020 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
More informationPreet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75
Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship
More information1.4 Arrays Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 2/6/11 12:33 PM!
1.4 Arrays Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 2/6/11 12:33 PM! A Foundation for Programming any program you might want
More informationCSE 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[]
More informationqwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui
More informationCS 121 Intro to Programming:Java - Lecture 11 Announcements
CS 121 Intro to Programming:Java - Lecture 11 Announcements Next Owl assignment up, due Friday (it s short!) Programming assignment due next Monday morning Preregistration advice: More computing? Take
More informationLOOPS 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
More informationHandout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.
Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java
More informationCSE 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
More informationAP Computer Science Java Mr. Clausen Program 9A, 9B
AP Computer Science Java Mr. Clausen Program 9A, 9B PROGRAM 9A I m_sort_of_searching (20 points now, 60 points when all parts are finished) The purpose of this project is to set up a program that will
More informationJava 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
More informationPerimeter, Area, and Volume
Perimeter, Area, and Volume Perimeter of Common Geometric Figures The perimeter of a geometric figure is defined as the distance around the outside of the figure. Perimeter is calculated by adding all
More informationBuilding 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
More informationAPPLICATIONS AND MODELING WITH QUADRATIC EQUATIONS
APPLICATIONS AND MODELING WITH QUADRATIC EQUATIONS Now that we are starting to feel comfortable with the factoring process, the question becomes what do we use factoring to do? There are a variety of classic
More informationChulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.
Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command
More informationIn 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
More informationChapter 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
More informationHandout 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:
More informationProgrammierpraktikum
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
More informationLab 5: Bank Account. Defining objects & classes
Lab 5: Bank Account Defining objects & classes Review: Basic class structure public class ClassName Fields Constructors Methods Three major components of a class: Fields store data for the object to use
More informationChapter 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
More informationUsing 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
More information13 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
More informationArea of a triangle: The area of a triangle can be found with the following formula: 1. 2. 3. 12in
Area Review Area of a triangle: The area of a triangle can be found with the following formula: 1 A 2 bh or A bh 2 Solve: Find the area of each triangle. 1. 2. 3. 5in4in 11in 12in 9in 21in 14in 19in 13in
More informationCompiler Construction
Compiler Construction Lecture 1 - An Overview 2003 Robert M. Siegfried All rights reserved A few basic definitions Translate - v, a.to turn into one s own language or another. b. to transform or turn from
More informationAP Computer Science Java Subset
APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall
More informationBuilding 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.
More informationIteration 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
More informationUnit 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
More informationHomework/Program #5 Solutions
Homework/Program #5 Solutions Problem #1 (20 points) Using the standard Java Scanner class. Look at http://natch3z.blogspot.com/2008/11/read-text-file-using-javautilscanner.html as an exampleof using the
More informationBuilding 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
More informationAP 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
More informationData Structures using OOP C++ Lecture 1
References: 1. E Balagurusamy, Object Oriented Programming with C++, 4 th edition, McGraw-Hill 2008. 2. Robert Lafore, Object-Oriented Programming in C++, 4 th edition, 2002, SAMS publishing. 3. Robert
More informationQuick Reference ebook
This file is distributed FREE OF CHARGE by the publisher Quick Reference Handbooks and the author. Quick Reference ebook Click on Contents or Index in the left panel to locate a topic. The math facts listed
More informationCharacteristics of the Four Main Geometrical Figures
Math 40 9.7 & 9.8: The Big Four Square, Rectangle, Triangle, Circle Pre Algebra We will be focusing our attention on the formulas for the area and perimeter of a square, rectangle, triangle, and a circle.
More informationChapter 2: Elements of Java
Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction
More informationObject-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
More informationChapter 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
More informationObject 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
More informationMoving 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
More informationArrays. Introduction. Chapter 7
CH07 p375-436 1/30/07 1:02 PM Page 375 Chapter 7 Arrays Introduction The sequential nature of files severely limits the number of interesting things you can easily do with them.the algorithms we have examined
More information5 Arrays and Pointers
5 Arrays and Pointers 5.1 One-dimensional arrays Arrays offer a convenient way to store and access blocks of data. Think of arrays as a sequential list that offers indexed access. For example, a list of
More informationSolutions to Homework 6
Solutions to Homework 6 Debasish Das EECS Department, Northwestern University ddas@northwestern.edu 1 Problem 5.24 We want to find light spanning trees with certain special properties. Given is one example
More informationFACTORING OUT COMMON FACTORS
278 (6 2) Chapter 6 Factoring 6.1 FACTORING OUT COMMON FACTORS In this section Prime Factorization of Integers Greatest Common Factor Finding the Greatest Common Factor for Monomials Factoring Out the
More informationContinuous Integration Part 2
1 Continuous Integration Part 2 This blog post is a follow up to my blog post Continuous Integration (CI), in which I described how to execute test cases in Code Tester (CT) in a CI environment. What I
More informationGrundlæggende Programmering IT-C, Forår 2001. Written exam in Introductory Programming
Written exam in Introductory Programming IT University of Copenhagen, June 11, 2001 English version All materials are permitted during the exam, except computers. The exam questions must be answered in
More information12-6 Write a recursive definition of a valid Java identifier (see chapter 2).
CHAPTER 12 Recursion Recursion is a powerful programming technique that is often difficult for students to understand. The challenge is explaining recursion in a way that is already natural to the student.
More informationIt has a parameter list Account(String n, double b) in the creation of an instance of this class.
Lecture 10 Private Variables Let us start with some code for a class: String name; double balance; // end Account // end class Account The class we are building here will be a template for an account at
More informationCSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Linda Shapiro Today Registration should be done. Homework 1 due 11:59 pm next Wednesday, January 14 Review math essential
More informationBasic Math for the Small Public Water Systems Operator
Basic Math for the Small Public Water Systems Operator Small Public Water Systems Technology Assistance Center Penn State Harrisburg Introduction Area In this module we will learn how to calculate the
More informationArrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.
Arrays Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html 1 Grid in Assignment 2 How do you represent the state
More informationF ahrenheit = 9 Celsius + 32
Problem 1 Write a complete C++ program that does the following. 1. It asks the user to enter a temperature in degrees celsius. 2. If the temperature is greater than 40, the program should once ask the
More informationKeystone National High School Placement Exam Math Level 1. Find the seventh term in the following sequence: 2, 6, 18, 54
1. Find the seventh term in the following sequence: 2, 6, 18, 54 2. Write a numerical expression for the verbal phrase. sixteen minus twelve divided by six Answer: b) 1458 Answer: d) 16 12 6 3. Evaluate
More informationStatements and Control Flow
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
More informationLine-based file processing
Line-based file processing reading: 6.3 self-check: #7-11 exercises: #1-4, 8-11 Hours question Given a file hours.txt with the following contents: 123 Kim 12.5 8.1 7.6 3.2 456 Brad 4.0 11.6 6.5 2.7 12
More informationMasters 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
More informationAP 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
More informationWA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.
WA2099 Introduction to Java using RAD 8.0 Student Labs Web Age Solutions Inc. 1 Table of Contents Lab 1 - The HelloWorld Class...3 Lab 2 - Refining The HelloWorld Class...20 Lab 3 - The Arithmetic Class...25
More informationProgramming Fundamentals I CS 110, Central Washington University. November 2015
Programming Fundamentals I CS 110, Central Washington University November 2015 Next homework, #4, was due tonight! Lab 6 is due on the 4 th of November Final project description + pseudocode are due 4th
More informationAn Incomplete C++ Primer. University of Wyoming MA 5310
An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages
More informationCalculating Area, Perimeter and Volume
Calculating Area, Perimeter and Volume You will be given a formula table to complete your math assessment; however, we strongly recommend that you memorize the following formulae which will be used regularly
More informationAssignment No.3. /*-- Program for addition of two numbers using C++ --*/
Assignment No.3 /*-- Program for addition of two numbers using C++ --*/ #include class add private: int a,b,c; public: void getdata() couta; cout
More informationUsing 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
More informationInstall Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html
CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install
More informationBasic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C
Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in
More informationIntroduction to Programming
Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems sjmaybank@dcs.bbk.ac.uk Spring 2015 Week 2b: Review of Week 1, Variables 16 January 2015 Birkbeck
More informationMore on Objects and Classes
Software and Programming I More on Objects and Classes Roman Kontchakov Birkbeck, University of London Outline Object References Class Variables and Methods Packages Testing a Class Discovering Classes
More information