System.out.printf("Please, enter the value of the base : \n"); base =input.nextint();
|
|
- Martha Hunt
- 5 years ago
- Views:
Transcription
1 CS141 Programming Assignment #6 Due Thursday, Dec 1st. 1) Write a method integerpower(base, exponent) that returns the value of base exponent For example, integerpower(3, 4) calculates 34 (or 3 * 3 * 3 * 3). Assume that exponent is a positive, nonzero integer and that base is an integer. Use for or while statement to control the calculation. Do not use any Math class methods. Incorporate this method into an application that reads integer values for base and exponent and performs the calculation with the integerpower method. * assignment 6 Q1 import java.util.scanner; public class q1 { public static int integerpower(int base, int exp){ int result = 1 ; for (int i = 0 ; i<exp ; i++ ) result*=base ; return result ; //end of integerpower method public static void main(string[] args) { int base, exp ; Scanner input = new Scanner(System.in); System.out.printf("Please, enter the value of the base : \n"); base =input.nextint(); System.out.printf("Please, enter the value of the exponent : \n"); exp = input.nextint(); System.out.printf("%d to the power %d = %d",base,exp,integerpower(base,exp)); //end of main 2) Define a method hypotenuse that calculates the hypotenuse of a right triangle when the lengths of the other two sides are given. The method should take two arguments of type double and return the hypotenuse as a double.
2 * assignment 6 Q2 import java.util.scanner ; public class q2 { public static double hypotenuse(double side1, double side2) { double hypsqr = Math.pow(side1, 2) + Math.pow(side2, 2) ; double hyp = Math.sqrt(hypsqr); return hyp ; //end of method public static void main(string[] args) { Scanner input = new Scanner(System.in); double side1, side2; /*read from the user System.out.print("Enter the value for Side 1: "); side1 = input.nextdouble(); System.out.print("Enter the value for Side 2: "); side2 = input.nextdouble(); System.out.printf("The length of the hypotenuse is: %.2f", hypotenuse(side1,side2)); //end of main //end of class 3) Define a method Celsius returns the Celsius equivalent of a Fahrenheit temperature, using the calculation Celsius = 5.0 / 9.0 * ( Fahrenheit - 32 ); * assignment 6 Q3 import java.util.scanner; public class q3 { public static double celsius(double Fahrenheit ){ return 5.0 / 9.0 * ( Fahrenheit - 32 ); //end of method public static void main(string[] args) {
3 Scanner input = new Scanner(System.in); System.out.printf("Please, enter a fahrenheit temperature : \n"); double temp =input.nextdouble(); System.out.printf("The equivalent celsius tempertaure= %.2f \n",celsius (temp) ); //end of class 4) Define a method Fahrenheit returns the Fahrenheit equivalent of a Celsius temperature, using the calculation Fahrenheit = 9.0 / 5.0 * Celsius + 32; Solution : * assignment 6 Q4 import java.util.scanner; public class q4{ public static double Fahrenheit(double Celsius ){ return 9.0 / 5.0 * Celsius + 32; //end of method public static void main(string[] args) { Scanner input = new Scanner(System.in); System.out.printf("Please, enter a celsius temperature : \n"); double temp =input.nextdouble(); System.out.printf("The equivalent fahrenheit tempertaure= %.2f \n", Fahrenheit(temp) ); //end of class 5) Write a class with the following methods: a) max( int [] a) Returns the maximum integer in the array. b) min(int [] a) Returns the minimum integer in the array. c) avergae(int [] a) Returns the average of integers in the array. d) sort(int [] a, int order) Sort the array in ASD or DES order. e) print(int [] a) Prints the array. f) equal(int [] a, int [] b) Return true if they are identical otherwise false g) firstnegative(int [] a) Return the index of the first negative found or -1 Test your class methods you implemented on the following array
4 int [] a = {10, 5, -6, 0, 15, -12, 20; Make sure to print out your answer after each method call. * assignment 6 Q5 public class q5{ public static int max( int a[] ) { int max = a[0]; for (int i=1; i<a.length ; i++){ if( a[i]> max) max = a[i]; //end of for return max ; //end of max method public static int min( int a[] ) { int min = a[0]; for (int i=1; i<a.length ; i++){ if(a[i]< min) min = a[i]; //end of for return min ; //end of min method public static double average( int a[] ) { double sum = 0; for (int i=0; i<a.length ; i++) sum+=a[i] ; return sum/a.length ; //end of average method public static void sort( int a[],int order ) { int temp; if (order == 1){ System.out.printf("Sorting ASD Order: \n"); for (int i = 0; i < a.length; i++) {
5 for (int j = i + 1; j < a.length; j++) { if (a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; // end of if // end of j for // end of i for // end of ASD if else if (order == 2){ System.out.printf("Sorting DSD Order: \n"); for (int i = 0; i < a.length; i++) { for (int j = i + 1; j < a.length; j++) { if (a[i] < a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; //end of if //end of j for //end of i for //end of DSD if //end of sort method public static void print( int a[] ) { for (int i = 0 ; i<a.length ; i++) System.out.printf("%d ",a[i]); //end of print method public static boolean equal( int a[],int b[] ) { boolean flag = true ; if (a.length!= b.length ) flag=false; else { for (int i = 0; i < a.length; i++){ if (a[i]!=b[i]) flag=false; return flag;
6 //end of equal method public static int firstnegative( int a[] ) { int index = -1 ; for(int i = 0 ;i<a.length ; i++){ if(a[i] < 0){ index = i ; break; //end of for return index ; //end of firstnegative method public static void main( String args[] ) { int [] a = {10, 5, -6, 0, 15, -12, 20; int [] b = { 5, -6, 0, 15, -12, 20; int [] c = { 20, 15, 10,5, 0, -6, -12; print(a); System.out.printf("the max is %d\n",max(a)); System.out.printf("the min is %d\n",min(a)); System.out.printf("the average is %2f\n",average(a)); sort(a,1); print(a); sort(a,2); print(a); System.out.printf("the index of the first negative is %d\n",firstnegative(a)); System.out.println("array b= "); print(b); if(equal(a,b)) System.out.printf("the two arrays a & b are equal \n"); else System.out.printf("the two arrays a & b are not equal \n"); System.out.println("array c= "); print(c); if(equal(a,c)) System.out.printf("the two arrays a & c are equal \n"); else System.out.printf("the two arrays a & c are not equal \n"); //end of class
7 6) Write a class with the following methods: h) max( int [][] a) Returns the maximum integer in the array. i) min(int [][] a) Returns the minimum integer in the array. j) avergae(int [][] a) Returns the average of integers in the array. k) copy(int [][] a,int [][]b) Copy array a to array b. l) print(int [][] a) Prints the array. Test your class methods you implemented on the following array int [][] a = {{10, 5, -6, 0,{11, 8, -2, 7,{4, 6, 2, 1,{9, -5, -3, 50; Make sure to print out your answer after each method call. * assignment 6 Q6 public class q6 { public static int max( int a[][] ) { int max =a[0][0] ; for(int i = 0 ; i<a.length ; i++) { for (int j=0; j<a[i].length ; j++){ if(max<a[i][j]) max = a[i][j]; //end of j for //end of i for return max ; //end of max method public static int min( int a[][] ) { int min = a[0][0]; for(int i = 0 ; i<a.length ; i++) { for (int j=0; j<a[i].length ; j++){ if(min>a[i][j]) min = a[i][j]; //end of j for //end of i for return min ; //end of max method
8 public static double average( int a[][] ) { double sum = 0; int count = 0 ; for (int i=0; i<a.length ; i++){ for (int j=0; j<a[i].length ; j++){ sum+=a[i][j]; count++ ; //end of j for // end of i for return sum/count ; //end of average method public static void copy( int a[][], int b[][] ) { for (int i=0; i<a.length ; i++){ for (int j=0; j<a[i].length ; j++){ b[i][j]=a[i][j]; // end of j for // end of i for //end of copy method public static void print( int a[][] ) { for (int i=0; i<a.length ; i++){ for (int j=0; j<a[i].length ; j++){ System.out.printf("%2d ",a[i][j]); // end of i for //end of print method public static void main(string args[]){ int [][] a = {{10, 5, -6, 0,{11, 8, -2, 7,{4, 6, 2, 1,{9, -5, -3, 50; int [][] b = new int [4][4] ; System.out.println("array a : "); print (a); System.out.printf("the max is %d\n",max(a)); System.out.printf("the min is %d\n",min(a)); System.out.printf("the average is %f\n",average(a)); System.out.println("array b before copying "); print (b); copy(a,b); System.out.println("array b after copying");
9 print (b); //end of main 7) Write a class that reads values of a two-dimensional integer array A[4][4] from the keyboard, and then computes values of integer array B[4], such that B[i] is the smallest value of i-th row of array A. * assignment 6 Q7 import java.util.scanner ; public class q7 { public static void readarray(int a[][]){ Scanner input = new Scanner(System.in); System.out.println("Please, Enter values of array a "); for(int i = 0 ; i<a.length ; i++){ for(int j = 0 ; j<a[i].length ; j++) a[i][j]=input.nextint(); //end of i for //end of read method public static void smallestofrow(int a[][], int b[]){ int min; for(int i = 0 ; i<a.length ; i++){ min = a[i][0]; for(int j = 1 ; j<a[i].length ; j++){ if (a[i][j]<min) min = a[i][j]; //end of j for b[i]=min ; //end of i for //end of mintob method public static void printarray1(int a[][]){ for(int i = 0 ; i<a.length ; i++){
10 for(int j = 0 ; j<a[i].length ; j++) System.out.printf("%2d ",a[i][j]); //end of i for //end of printarray method public static void printarray2(int a[]){ for(int i = 0 ; i<a.length ; i++){ System.out.printf("%2d ",a[i]); //end of i for //end of printarray method public static void main(string args[]){ //end of main // end of class q7 int a[][] = new int[4][4]; int b[] = new int[4] ; readarray(a); smallestofrow(a,b); System.out.printf("Array A: \n"); printarray1(a); System.out.printf("Array B: \n"); printarray2(b); 8) Write a class Matrix with the following methods: -setmatrix( int row, int col) Sets the matrix array size to row and col -setmatrixarray(int [][] m) Sets the matrix array to the values given by m -print() Prints the matrix array -fill () Sets the matrix array values by the user -add(matrix a) Add the 2 matrices -sub(matrix a) Subtract the two matrices -mul(matrix a) Multiply the two matrices Test your class methods you implemented on the following Matrices A= B= Make sure to print out your answer after each method call.
11 * assignment 6 Q8 * import java.util.scanner ; public class q8 { static int matrix[][] ; public static void setmatrix( int row, int col) { matrix = new int [row][col]; //end of setmatrix method public static void setmatrixarray(int [][] m) { for (int i=0; i<matrix.length ; i++){ for (int j=0; j<matrix[i].length ; j++){ matrix[i][j]= m[i][j]; // end of i for //end of setmatrixarray method public static void print( ) { for (int i=0; i<matrix.length ; i++){ for (int j=0; j<matrix[i].length ; j++){ System.out.printf("%2d ",matrix[i][j]); // end of i for //end of print method public static void fill() { Scanner input = new Scanner(System.in) ; System.out.printf("Please,enter the values of the matrix\n"); for (int i=0; i<matrix.length ; i++){ for (int j=0; j<matrix[i].length ; j++){ matrix[i][j] = input.nextint();; // end of i for //end of fill method public static void add(int [][]a) {
12 for (int i=0; i<matrix.length ; i++){ for (int j=0; j<matrix[i].length ; j++){ matrix[i][j]+=a[i][j] ; // end of i for //end of add method public static void sub(int [][]a) { for (int i=0; i<matrix.length ; i++){ for (int j=0; j<matrix[i].length ; j++){ matrix[i][j]-=a[i][j] ; // end of i for //end of add method public static void mul(int [][]a) { int c[][] = new int [matrix.length][matrix[0].length] ; for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[0].length; j++) { for (int k = 0; k < matrix[0].length; k++) { c[i][j] += matrix[i][k] * a[k][j]; for(int i =0 ;i<matrix.length ; i++) for(int j = 0 ;j<matrix[i].length ; j++) matrix[i][j] = c[i][j] ; //end of mul method public static void main(string args[]) { int b[][] = {{8, 0,1,{-4, 10, 7, {5, 2, -2 ; System.out.println("Setting the matrix to 3 X 3 :"); setmatrix(3,3) ; print(); System.out.println("Setting the matrix to values of matrix b:"); setmatrixarray(b); print(); System.out.println("Setting the matrix to your values:"); fill();
13 print() ; System.out.println("adding to the matrix:"); add(b); print() ; System.out.println("subtracting from the matrix:"); sub(b); print() ; System.out.println("multyplying the matrix:"); mul(b); print() ; //end of main
CS141 Programming Assignment #5
CS141 Programming Assignment #5 Due Wednesday, Nov 16th. 1) Write a class that asks the user for the day number (0 to 6) and prints the day name (Saturday to Friday) using switch statement. Solution 1:
More informationCS141 Programming Assignment #10
CS141 Programming Assignment #10 Due Sunday, May 5th. 1) Write a class with the following methods: a) max( int [][] a) Returns the maximum integer in the array. b) min(int [][] a) Returns the minimum integer
More informationIntroduction. Data in a table or a matrix can be represented using a two-dimensional array. For example:
Chapter 7 MULTIDIMENSIONAL ARRAYS Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk ١ Introduction Data in a table or a matrix can be
More information1. What is the difference between a compiler and an interpreter? Also, discuss Java s method.
Name: Write all of your responses on these exam pages. 1 Short Answer (5 Points Each) 1. What is the difference between a compiler and an interpreter? Also, discuss Java s method. 2. Java is a platform-independent
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 information1 Short Answer (10 Points Each)
1 Short Answer (10 Points Each) 1. For the following one-dimensional array, show the final array state after each pass of the three sorting algorithms. That is, after each iteration of the outside loop
More informationCS141 Programming Assignment #6
CS141 Programming Assignment #6 Due Sunday, Nov 18th. 1) Write a class with methods to do the following output: a) 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1 b) 1 2 3 4 5 4 3 2 1 1 2 3 4 * 4 3 2 1 1 2 3 * * * 3 2 1
More informationIt is a constructor and is called using the new statement, for example, MyStuff m = new MyStuff();
COSC 117 Exam 3 Key Fall 2012 Part 1: Definitions & Short Answer (3 Points Each) 1. A method in a class that has no return type and the same name as the class is called what? How is this type of method
More information1 Short Answer (7 Points Each)
1 Short Answer ( Points Each) 1. Write a linear search method for an integer array that takes in an array and target value as parameters and returns the first position of the target in the array. If the
More informationObject Oriented Programming. Java-Lecture 6 - Arrays
Object Oriented Programming Java-Lecture 6 - Arrays Arrays Arrays are data structures consisting of related data items of the same type In Java arrays are objects -> they are considered reference types
More informationReading array int x[10]; for(i=0; i<=9; i++) {
* Examples: int a[10]; // declare int array of 10 elements float x[5]; int a=0, x[5]=0; int b[5]=7, 2, 3, 1, 6; // where b[0]=7, b[1]=2, b[2]=3, b[3]=1, b[4]=6 Reading array int x[10]; for(i=0; i
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 Final Exam Spring 2011 Name: Part 1: Definitions & Short Answer (3 Points Each) 1. What do CPU and ALU stand for? 2. What are the two main components to the CPU and what do each of them do? 3.
More informationLiang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
1 Thus far, you have used one-dimensional arrays to model linear collections of elements. You can use a two-dimensional array to represent a matrix or a table. For example, the following table that describes
More information1 Short Answer (10 Points Each)
Name: Write all of your responses on these exam pages. 1 Short Answer (10 Points Each) 1. What is the difference between a compiler and an interpreter? Also, discuss how Java accomplishes this task. 2.
More informationWentworth Institute of Technology. Engineering & Technology WIT COMP1000. Arrays
WIT COMP1000 Arrays Arrays An array is a list of variables of the same type, that represents a set of related values For example, say you need to keep track of the cost of 1000 items You could declare
More informationCS141 Programming Assignment #8
CS141 Programming Assignment #8 Due Sunday, April 14th. 1- Write a class with methods to do the following output: a) 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1 b) 1 2 3 4 5 4 3 2 1 1 2 3 4 * 4 3 2 1 1 2 3 * * * 3 2
More informationFundamentals of Programming Data Types & Methods
Fundamentals of Programming Data Types & Methods By Budditha Hettige Overview Summary (Previous Lesson) Java Data types Default values Variables Input data from keyboard Display results Methods Operators
More information2 marks. class q1c{ class point{ int p,q; point(int p, int q){ this.p=p; this.q=q; } void printpoint(){ System.out.println(this.p+" "+this.
Question1. What will be the output of the following programs? Give reasons. [4, 7, 4] No credit will be given if you do not give reasons (even if your output is correct). Also, if the reasoning is wrong
More information1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall 2002
1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall 2002 Name: TA s Name: Tutorial: For Graders Question 1 Question 2 Question 3 Question 4 Question 5 Total Problem 1 (10 Points).
More information1 Short Answer (10 Points Each)
COSC 117 Exam # Solutions Fall 01 1 Short Answer (10 Points Each) 1. Write a declaration for a two dimensional array of doubles that has 1 rows and 17 columns. Then write a nested for loop that populates
More informationComputer programming Code exercises [1D Array]
Computer programming-140111014 Code exercises [1D Array] Ex#1: //Program to read five numbers, from user. public class ArrayInput public static void main(string[] args) Scanner input = new Scanner(System.in);
More informationWentworth Institute of Technology. Engineering & Technology WIT COMP1000. Methods
WIT COMP1000 Methods Methods Programs can be logically broken down into a set of tasks Example from horoscope assignment:» Get input (month, day) from user» Determine astrological sign based on inputs
More informationChapter 8 Multi-Dimensional Arrays
Chapter 8 Multi-Dimensional Arrays 1 1-Dimentional and 2-Dimentional Arrays In the previous chapter we used 1-dimensional arrays to model linear collections of elements. myarray: 6 4 1 9 7 3 2 8 Now think
More informationESC101 : Fundamental of Computing
ESC101 : Fundamental of Computing End Semester Exam 19 November 2008 Name : Roll No. : Section : Note : Read the instructions carefully 1. You will lose 3 marks if you forget to write your name, roll number,
More informationCS111: PROGRAMMING LANGUAGE II
1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1: Introduction Lecture Contents 2 Course info Why programming?? Why Java?? Write once, run anywhere!! Java basics Input/output Variables
More informationArrays. Arrays. Wolfgang Schreiner Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria
Arrays Wolfgang Schreiner Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria Wolfgang.Schreiner@risc.jku.at http://www.risc.jku.at Wolfgang Schreiner RISC Arrays
More informationCOE 212 Engineering Programming. Welcome to the Final Exam Tuesday December 15, 2015
1 COE 212 Engineering Programming Welcome to the Final Exam Tuesday December 15, 2015 Instructors: Dr. Salim Haddad Dr. Bachir Habib Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1.
More informationLecture 2. Two-Dimensional Arrays
Lecture 2 Two-Dimensional Arrays 1 Lecture Content 1. 2-D Array Basics 2. Basic Operations on 2-D Array 3. Storing Matrices with Special Properties 4. Applications of 2-D Array 2 1. 2-D Array Basics An
More informationChapter 8 Multidimensional Arrays
Chapter 8 Multidimensional Arrays 8.1 Introduction Thus far, you have used one-dimensional arrays to model linear collections of elements. You can use a two-dimensional array to represent a matrix or a
More informationArrays and Lists Review CSC 123 Fall 2018 Howard Rosenthal
Arrays and Lists Review CSC 123 Fall 2018 Howard Rosenthal Lesson Goals Review what an array is Review how to declare arrays Review what reference variables are Review how to pass arrays to methods Review
More informationCS Computers & Programming I Review_01 Dr. H. Assadipour
CS 101 - Computers & Programming I Review_01 Dr. H. Assadipour 1. What is the output of this program? public class Q_01 public static void main(string [] args) int x=8; int y=5; double z=12; System.out.println(y/x);
More informationComputer Programming, I. Laboratory Manual. Experiment #9. Multi-Dimensional Arrays
Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #9
More informationArrays. Eng. Mohammed Abdualal
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 9 Arrays
More informationChapter 01 Arrays Prepared By: Dr. Murad Magableh 2013
Chapter 01 Arrays Prepared By: Dr. Murad Magableh 2013 One Dimensional Q1: Write a program that declares two arrays of integers and fills them from the user. Then exchanges their values and display the
More informationUniversity of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007
Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2007 Final Examination Question Max
More informationwhile (/* array size less than 1*/){ System.out.print("Number of students is invalid. Enter" + "number of students: "); /* read array size again */
import java.util.scanner; public class CourseManager1 { public static void main(string[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter number of students: "); /* read the number
More informationMultidimensional Arrays. CSE 114, Computer Science 1 Stony Brook University
Multidimensional Arrays CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Multidimensional Arrays How do we represent matrices or tables? A two-dimensional array
More informationWarm up Exercise. What are the types and values of the following expressions: * (3 + 1) 3 / / 2.0 (int)1.0 / 2
Warm up Exercise What are the types and values of the following expressions: 3.0+4 * (3 + 1) 3 / 2 + 1.0 1.0 / 2.0 (int)1.0 / 2 COMP-202 - Programming Basics 1 Warm up Exercise What are the types and values
More informationChapter 6 Arrays. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.
Chapter 6 Arrays 1 Opening Problem Read one hundred numbers, compute their average, and find out how many numbers are above the average. 2 Solution AnalyzeNumbers Run Run with prepared input 3 Objectives
More information3/18/2015. Chapter 19 Sorting and Searching SELECTION SORT SORTING AN ARRAY OF INTEGERS SORTING AN ARRAY OF INTEGERS FILE SELECTIONSORTER.
Chapter 19 Sorting and Searching The Plan For Today AP Test Chapter 18 Quiz Corrections Chapter 18 Assignment Due Today Chapter 19 19.1: Selection Sort 19.2: Profiling the Selection Sort Algorithm 19.3:
More informationCS 170 Exam 2. Section 004 Fall Name (print): Instructions:
CS 170 Exam 2 Section 004 Fall 2013 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 informationJump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.
Jump Statements The keyword break and continue are often used in repetition structures to provide additional controls. break: the loop is terminated right after a break statement is executed. continue:
More informationChapter 2. Elementary Programming
Chapter 2 Elementary Programming 1 Objectives To write Java programs to perform simple calculations To obtain input from the console using the Scanner class To use identifiers to name variables, constants,
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 informationCIS 1068 Netflix Challenge New assignment posted soon Lab grades November 14, 2017
Administrative Stuff CIS 1068 Netflix Challenge New assignment posted soon Lab grades November 14, 2017 Last Time. Building Our Own Classes Why Abstraction More on the new operator Fields Class vs the
More informationJump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.
Jump Statements The keyword break and continue are often used in repetition structures to provide additional controls. break: the loop is terminated right after a break statement is executed. continue:
More informationArrays. int Data [8] [0] [1] [2] [3] [4] [5] [6] [7]
Arrays Arrays deal with storage of data, which can be processed later. Arrays are a series of elements (variables) of the same type placed consecutively in memory that can be individually referenced by
More informationa) Answer all questions. b) Write your answers in the space provided. c) Show all calculations where applicable.
Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2008 January Exam Question Max Internal
More informationCS141 Programming Assignment #4
Due Monday, Oct 31. CS141 Programming Assignment #4 1- Write a program to read in 10 numbers and compute the average, maximum and minimum values (using both while and for loop). Solution 1: * assignment
More informationLearning objec-ves. Declaring and ini-alizing 2D arrays. Prin-ng 2D arrays. Using 2D arrays Decomposi-on of a solu-on into objects and methods
Learning objec-ves 2D Arrays (Savitch, Chapter 7.5) TOPICS Using 2D arrays Decomposi-on of a solu-on into objects and methods Multidimensional Arrays 2D Array Allocation 2D Array Initialization TicTacToe
More informationIntroduction to Computer Science Unit 2. Notes
Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and
More informationChoose 3 of the 1 st 4 questions (#'s 1 through 4) to complete. Each question is worth 12 points.
Choose 3 of the 1 st 4 questions (#'s 1 through 4) to complete. Each question is worth 12 points. Use the remaining question as extra credit (worth 1/2 of the points earned). Specify which question is
More information1 Definitions & Short Answer (5 Points Each)
Fall 2013 Final Exam COSC 117 Name: Write all of your responses on these exam pages. If you need more space please use the backs. Make sure that you show all of your work, answers without supporting work
More informationM105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014
M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014 Question One: Choose the correct answer and write it on the external answer booklet. 1. Java is. a. case
More informationChapter 7 Multidimensional Arrays. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.
Chapter 7 Multidimensional Arrays rights reserved. 1 Motivations Thus far, you have used one-dimensional arrays to model linear collections of elements. You can use a two-dimensional array to represent
More informationCS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University
9/5/6 CS Introduction to Computing II Wayne Snyder Department Boston University Today: Arrays (D and D) Methods Program structure Fields vs local variables Next time: Program structure continued: Classes
More informationCSE Fall 2015 Section 002 Exam 2, Time: 80 mins
CSE 1310 - Fall 2015 Section 002 Exam 2, Time: 80 mins Name:. Student ID:. Total exam points: 100. Question Points Out of 1 20 2 20 3 20 4 20 5 20 6 20 Total 100 SOLVE 5 OUT 6 PROBLEMS. You must specify
More informationDeclaring and ini,alizing 2D arrays
Declaring and ini,alizing 2D arrays 4 2D Arrays (Savitch, Chapter 7.5) TOPICS Multidimensional Arrays 2D Array Allocation 2D Array Initialization TicTacToe Game // se2ng up a 2D array final int M=3, N=4;
More informationCOE 212 Engineering Programming. Welcome to the Final Exam Thursday December 15, 2016
1 COE 212 Engineering Programming Welcome to the Final Exam Thursday December 15, 2016 Instructors: Dr. Salim Haddad Dr. Bachir Habib Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1.
More information1 class Lecture5 { 2 3 "Arrays" 4. Zheng-Liang Lu Java Programming 136 / 174
1 class Lecture5 { 2 3 "Arrays" 4 5 } Zheng-Liang Lu Java Programming 136 / 174 Arrays An array stores a large collection of data which is of the same type. 2 // assume the size variable exists above 3
More informationCEN 414 Java Programming
CEN 414 Java Programming Instructor: H. Esin ÜNAL SPRING 2017 Slides are modified from original slides of Y. Daniel Liang WEEK 2 ELEMENTARY PROGRAMMING 2 Computing the Area of a Circle public class ComputeArea
More informationProgramming with Java
Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules
More informationChapter 7 Multidimensional Arrays
Chapter 7 Multidimensional Arrays 1 Motivations You can use a two-dimensional array to represent a matrix or a table. Distance Table (in miles) Chicago Boston New York Atlanta Miami Dallas Houston Chicago
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 informationTutorial 11. Exercise 1: CSC111 Computer Programming I. A. Write a code snippet to define the following arrays:
College of Computer and Information Sciences CSC111 Computer Programming I Exercise 1: Tutorial 11 Arrays: A. Write a code snippet to define the following arrays: 1. An int array named nums of size 10.
More informationComputer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming
Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #2
More informationCS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University
CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Arrays A data structure for a collection of data that is all of the same data type. The data type can be
More informationComputação I. Exercises. Leonardo Vanneschi NOVA IMS, Universidade Nova de Lisboa. Leonardo Vanneschi Computação I NOVA IMS
Computação I Exercises Leonardo Vanneschi NOVA IMS, Universidade Nova de Lisboa 1 Exercise 1 Write a Java program composed by: a. A method called myaverage that has the following parameters: an array A
More informationInstructor: Yu Wang 11/16/2012
CS170 SECTION 001 INTRODUCTION TO COMPUTER SCIENCE I, FALL 2012 Midterm Exam II Instructor: Yu Wang 11/16/2012 Name: Emory Alias: INSTRUCTIONS: Keep your eyes on your own paper and do your best to prevent
More informationArrays and Array Lists. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos and Alexandra Stefan University of Texas at Arlington
Arrays and Array Lists CSE 1310 Introduction to Computers and Programming Vassilis Athitsos and Alexandra Stefan University of Texas at Arlington 1 Motivation Current limitation: We cannot record multiple
More informationLab Assignment Three
Lab Assignment Three C212/A592 Fall Semester 2010 Due in OnCourse by Friday, September 17, 11:55pm (Dropbox will stay open until Saturday, September 18, 11:55pm) Abstract Read and solve the problems below.
More informationArrays and Lists CSC 121 Fall 2016 Howard Rosenthal
Arrays and Lists CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand what an array is Understand how to declare arrays Understand what reference variables are Understand how to pass arrays to methods
More informationProblems with simple variables
Problems with simple variables Hard to give up values high number of variables. Complex to sort a high number of variables by value. Impossible to use loops. Example problem: Read one hundred numbers,
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 informationIntroduction to Computer Science Unit 2. Notes
Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and
More informationARRAYS. Java Programming
5 ARRAYS 144 Objectives Declare and create arrays of primitive, class, or array types Explain why elements of an array are initialized Given an array definition, initialize the elements of an array Determine
More informationCS18000: Programming I
CS18000: Programming I Introduction to Concurrency January 20, 2010 Prof. Chris Clifton Today We Learn Functions as Abstractions A First View of Concurrency Threads 1/21/2010 CS18000 2 Prof. Chris Clifton
More informationSorting Algorithms part 1
Sorting Algorithms part 1 1. Bubble sort Description Bubble sort is a simple sorting algorithm. It works by repeatedly stepping through the array to be sorted, comparing two items at a time, swapping these
More informationComplexity, General. Standard approach: count the number of primitive operations executed.
Complexity, General Allmänt Find a function T(n), which behaves as the time it takes to execute the program for input of size n. Standard approach: count the number of primitive operations executed. Standard
More informationIntroduction to Algorithms and Data Structures
Introduction to Algorithms and Data Structures Lecture 4 Structuring Data: Multidimensional Arrays, Arrays of Objects, and Objects Containing Arrays Grouping Data We don t buy individual eggs; we buy them
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 informationLoops. Eng. Mohammed Abdualal. Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 6 Loops
More informationControl Structures: if and while A C S L E C T U R E 4
Control Structures: if and while A C S - 1903 L E C T U R E 4 Control structures 3 constructs are essential building blocks for programs Sequences compound statement Decisions if, switch, conditional operator
More informationComputer Science & Engineering 150A Problem Solving Using Computers
Computer Science & Engineering 150A Problem Solving Using Computers Lecture 06 - Stephen Scott Adapted from Christopher M. Bourke 1 / 30 Fall 2009 Chapter 8 8.1 Declaring and 8.2 Array Subscripts 8.3 Using
More informationCS S-08 Arrays and Midterm Review 1
CS112-2012S-08 Arrays and Midterm Review 1 08-0: Arrays ArrayLists are not part of Java proper 08-1: Arrays Library class Created using lower-level Java construct: Array Arrays are like a stripped-down
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 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 informationChapter 6 Single-Dimensional Arrays. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
Chapter 6 Single-Dimensional Arrays rights reserved. 1 Opening Problem Read one hundred numbers, compute their average, and find out how many numbers are above the average. Solution AnalyzeNumbers rights
More informationHandout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8. Handout 5. Loops.
Handout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8 Handout 5 Loops. Loops implement repetitive computation, a k a iteration. Java loop statements: while do-while for 1. Start with the while-loop.
More informationCS 101 Spring 2007 Midterm 2 Name: ID:
You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure
More informationCS110 Programming Language I. Lab 6: Multiple branching Mechanisms
CS110 Programming Language I Lab 6: Multiple branching Mechanisms Computer Science Department Fall 2016 Lab Objectives: In this lab, the student will practice: Using switch as a branching mechanism Lab
More informationArrays and Lists CSC 121 Fall 2015 Howard Rosenthal
Arrays and Lists CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand what an array is Understand how to declare arrays Understand what reference variables are Understand how to pass arrays to methods
More informationQuestion: Total Points: Score:
CS 170 Exam 2 Section 002 Fall 2013 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 informationArrays: An array is a data structure that stores a sequence of values of the same type. The data type can be any of Java s primitive types:
Arrays: An array is a data structure that stores a sequence of values of the same type. The data type can be any of Java s primitive types: int, short, byte, long, float, double, boolean, char The data
More informationAhmadu Bello University Department of Mathematics First Semester Examinations June 2014 COSC211: Introduction to Object Oriented Programming I
Ahmadu Bello University Department of Mathematics First Semester Examinations June 2014 COSC211: Introduction to Object Oriented Programming I Attempt Four questions Time: 120 mins 1. Examine the following
More informationExample: Monte Carlo Simulation 1
Example: Monte Carlo Simulation 1 Write a program which conducts a Monte Carlo simulation to estimate π. 1 See https://en.wikipedia.org/wiki/monte_carlo_method. Zheng-Liang Lu Java Programming 133 / 149
More informationAttendance (2) Performance (3) Oral (5) Total (10) Dated Sign of Subject Teacher
Attendance (2) Performance (3) Oral (5) Total (10) Dated Sign of Subject Teacher Date of Performance:... Actual Date of Completion:... Expected Date of Completion:... ----------------------------------------------------------------------------------------------------------------
More informationAdministrivia. HW on recursive lists due on Wednesday. Reading for Wednesday: Chapter 9 thru Quicksort (pp )
Sorting 4/23/18 Administrivia HW on recursive lists due on Wednesday Reading for Wednesday: Chapter 9 thru Quicksort (pp. 271-284) A common problem: Sorting Have collection of objects (numbers, strings,
More informationLAB 7. Objectives: Navin Sridhar D 8 54
LAB 7 Objectives: 1. Learn to create and define constructors. 2. Understand the use and application of constructors & instance variables. 3. Experiment with the various properties of arrays. 4. Learn to
More informationJava Classes: Math, Integer A C S L E C T U R E 8
Java Classes: Math, Integer A C S - 1903 L E C T U R E 8 Math class Math class is a utility class You cannot create an instance of Math All references to constants and methods will use the prefix Math.
More information