CS141 Programming Assignment #8
|
|
- Augustine Berry
- 6 years ago
- Views:
Transcription
1 CS141 Programming Assignment #8 Due Sunday, April 14th. 1- Write a class with methods to do the following output: a) b) * * * * * * * * * * * * * * * * * * * * * * * * * c) Read odd integer x and the output depended on x for example: x = 5 x=7 * * *** *** ***** ***** *** ******* * ***** *** * //Assignment# 8 Q1 //Due Date: April 14th,2013 //This program will output three different shapes using three different methods. import java.util.scanner; public class Q1 { methoda(); methodb(); System.out.print("Enter an odd integer: "); int num = input.nextint(); methodc(num); /** Method to print the first shape mentioned above **/ public static void methoda (){ for (int i = 5; i >= 1; i--){ for (int j = 5; j > i; j--){ System.out.print( " " ); for (int j = 1; j <= i; j++){ System.out.print(i+" ");
2 /** Method to print the second shape mentioned above **/ public static void methodb(){ for (int i = 5; i >= 1; i--){ for (int j = 1; j <= i; j++) System.out.print(j+" "); for (int j = i; j < 5; j++) System.out.print("* "); for (int j = i; j < 4; j++) System.out.print("* "); for (int j = i; j >= 1; j--){ if (j == 5) continue; System.out.print(j+" "); for (int i = 2; i <= 5; i++){ for (int j = 1; j <= i; j++) System.out.print(j+" "); for (int j = i; j < 5; j++) System.out.print("* "); for (int j = i; j < 4; j++) System.out.print("* "); for (int j = i; j >= 1; j--){ if (j == 5) continue; System.out.print(j+" "); /** Method to print the third shape mentioned above **/ public static void methodc(int x){ if(x%2!= 0){ for (int i = 1; i <= x; i+=2){ for (int j = 1; j <= (x - i)/2; j++) System.out.print(" "); for (int j = 1; j <= i; j++) System.out.print("*"); for (int i = x-2; i >= 1; i-=2){ for (int j = 1; j <= (x - i)/2; j++) System.out.print(" "); for (int j = 1; j <= i; j++) System.out.print("*"); System.out.printf("Error!! %d is not odd!!", x); // end class
3 2- Write a program that have a menu of 4 options: Please choose from the menu: 1- Print a number digits. 2- Calculate the sum between two integers. 3- Find all numbers divisible by a number in a given range. 4- Exit Option 1 asks for a positive integer number n and prints its digits. Example: Please enter a positive integer: = Option 2 asks for two integers start and end then it finds the sum of all the integers between start and end. Example: Please enter the start and the end integers: 2 6 The sum for all numbers between 2 and 6 = 12 Option 3 asks for three integers start, end and a number then it finds those integers between start and end that are divisible by the number and prints them. Example: Please enter the start and the end integers: 1 10 Please enter the number you want to check for: 3 The numbers are divisible by 3 is : Option 4 Exit the program. //Assignment# 8 Q2 //Due Date: April 14th,2013 //This program is Menu driven program options: // 1)print a given number's digits // 2)calculate the sum between two integers // 3)find all numbers divisible by a number in a given range //4)Exit.
4 import java.util.scanner; public class Q2 { int choice; // stores the user's choice from the menu do{ System.out.println("Please choose from the menu:\n"); System.out.println("1-Print the number's digits."); System.out.println("2-Calculate the sum between two integers."); System.out.println("3-Find all numbers divisible by a number" + " in a given range."); System.out.println("4-Exit."); choice = input.nextint(); switch(choice){ case 1: printdigits(); case 2: printsum(); case 3: printdivisors(); case 4: System.out.println("Bye!!"); default:system.out.println("invalid input. Try again!!"); while (choice!= 4); /** method to print the digits in the number **/ public static void printdigits(){ Scanner input = new Scanner (System.in); int num,numcopy,places=0, factor=1; System.out.println("Please enter a positive integer: "); num = input.nextint(); numcopy= num; while(numcopy >0){ // to count how many digits in the number numcopy/=10; places++; places--; while(places >0){ // build the factor that will divide the num factor*=10; places--; System.out.printf("%d=", num); while(num >0){ //brake num from left to right. numcopy =num % factor ; num/= factor; System.out.printf(" %d", num); factor/=10; num=numcopy;
5 /** method to print the sum of numbers between a range **/ public static void printsum(){ int start; // stores the starting value of the range int end; // stores the ending value of the range int sum = 0; // stores the sum of the value between the range System.out.println("Please enter the start and the end integers:"); start = input.nextint(); end = input.nextint(); for (int i = start+1; i < end; i++) sum += i; System.out.printf("The sum for all numbers between %d ", start); System.out.printf("and % d = %d\n", end, sum); /** method to find the numbers divisible by a certain number **/ public static void printdivisors(){ Scanner input = new Scanner (System.in); int start; // stores the beginning of the range int end; // stores the end of the range int num; // stores the number to check for divisibility of System.out.println("Please enter the start and end integers:"); start = input.nextint(); end = input.nextint(); System.out.println("Please enter the number you want to check for:"); num = input.nextint(); System.out.printf("The numbers are divisible by %d is:\n", num); for (int i = start+1; i < end; i++) if (i % num == 0) System.out.printf("%d ", i); //end class 3- Write a class that reads 10 integers. The program should calculate and print the sum of even and odd numbers. You program should have three methods: - Read method that will be responsible for reading the numbers. - IsOdd a Boolean function that checks if a number is odd or not. - IsEven a Boolean function that checks if a number is even or not. Example: Please enter 10 integers: The sum of odd elements is: 25 The sum of even elements is: 30 //Assignment# 8 Q3 //Due Date: April 14th,2013 //This program will find the sum of the even and the sum of the odd numbers.
6 import java.util.scanner; public class Q4 { private static int sumeven; //stores the sum of the even numbers private static int sumodd; //stores the sum of the odd numbers Read(); System.out.printf("The sum of odd elements is: %d\n",sumodd); System.out.printf("The sum of even elements is: %d\n",sumeven); /** Method to read 10 numbers and compute the sum of the even ** ** and the sum of the odd numbers **/ public static void Read(){ sumeven = sumodd = 0; System.out.println("Please enter 10 integers: "); for (int i = 1; i <= 10; i++){ int num = input.nextint(); //stores number the user input if(isodd(num)) sumodd+=num; if(iseven(num)) sumeven+=num; /** Method to check if value is odd **/ public static boolean IsOdd(int x){ if (x%2 == 0) return false; return true; /** Method to check if value is even **/ public static boolean IsEven(int x){ if (x%2 == 0) return true; return false; //end class 4- Write a class that reads 8 integers and finds the largest and the smallest numbers. The main should print the large and small numbers. Example: Please enter 8 integers: The largest number is: 11 The smallest number is: -6 //Assignment# 8 Q4
7 //Due Date: April 14th,2013 //This program will read 8 numbers and print the largest and smallest of them. import java.util.scanner; public class Q4 { private static int large; private static int small; Read(); System.out.printf("The largest number is: %d\n", large); System.out.printf("The smallest number is: %d\n", small); //end main /** Method to read values and find largest and smallest values **/ public static void Read(){ System.out.println("Please enter 8 integers:"); int num = input.nextint(); large = small = num; for (int i = 2; i <=8; i++){ num = input.nextint(); large = Math.max(large, num); small = Math.min(small, num); //end class 5- Write a class that read a birthday as three integers day, month and year. It passes these three integers to a method that finds the age. Assume that we checking for the age until 1/1/2013. Example: Please enter your Birthday as 3 numbers DD MM YYYY: Your age is: 63 years 0 months and 0 days //Assignment# 8 Q5 //Due Date: April 14th,2013 //This program will read a birthday and finds the age until 1/1/2013. import java.util.scanner; public class Q5 { private static int years; // stores the number of years private static int months;// stores the number of months private static int days; // stores the number of days readage(); System.out.println("Your age is:"); System.out.printf("%d years %d months and %d days\n", years, months, days);
8 /** Method to read the day, month and year from the user then **/ /** call another method to compute the age **/ public static void readage() { int yyyy; // stores the birth year int mm; // stores the birth month int dd; // stores the birth day boolean ok;// stores flag for the loop System.out.println("Please enter your Birthday as 3 numbers DD MM YYYY:"); do { dd = input.nextint(); mm = input.nextint(); yyyy = input.nextint(); ok = false; if (yyyy < 0) // check if year is valid System.out.println("Years cannot be negative!!!"); if (mm > 12 mm < 0) // check if month is valid System.out.println("Months should be between 1 and 12!!!"); if ((dd < 0 dd > 31) (dd > 30 && (mm == 4 mm == 6 mm ==9 mm == 11)) (dd > 28 && mm == 2 && yyyy % 4!= 0) (dd > 29 && mm == 2)) // check if day is valid System.out.println("day does not exist in the given month!!!"); if (yyyy > 2012 ) //check day is not after given "until" date System.out.println("Dates must be before 01/01/2013!!!"); ok = true; if (!ok) // if invalid date System.out.println("Please enter the date again (DD MM YYYY):"); while (!ok); findage(dd, mm, yyyy); // end readage /** Method to compute the age **/ public static void findage(int d, int m, int y) { years = y; months = 12 - m; if (d == 1) { days = 0; months++; switch (m) { case 4: case 6: case 9:case 11: days = 31 - d; case 2: if (y % 4 == 0) days = 30 - d; days = 29 - d; default: days = 32 - d;
9 if ((years==0 )&& (months ==12) && (days ==0 )) //special case { years= 1; months=0; days =0 ; // end findage // end class
CS141 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 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 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 informationCS141 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 informationAL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I
AL GHURAIR UNIVERSITY College of Computing CSC 209 JAVA I week 2- Arithmetic and Decision Making: Equality and Relational Operators Objectives: To use arithmetic operators. The precedence of arithmetic
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 informationIntroduction to Java Applications
2 Introduction to Java Applications OBJECTIVES In this chapter you will learn: To write simple Java applications. To use input and output statements. Java s primitive types. Basic memory concepts. To use
More informationBasic Problem solving Techniques Top Down stepwise refinement If & if else.. While.. Counter controlled and sentinel controlled repetition Usage of
Basic Problem solving Techniques Top Down stepwise refinement If & if.. While.. Counter controlled and sentinel controlled repetition Usage of Assignment increment & decrement operators 1 ECE 161 WEEK
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 informationdownload instant at
2 Introduction to Java Applications: Solutions What s in a name? That which we call a rose By any other name would smell as sweet. William Shakespeare When faced with a decision, I always ask, What would
More informationMenu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by:
Menu Driven Systems While loops, menus and the switch statement Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list while loops recap
More informationExam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:
كلية الحاسبات وتقنية المعلوما Exam 2 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: November 22, 2015 Student Name: Student ID: Total Marks: 40 Obtained Marks: Instructions: Do not open this
More informationAL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I
AL GHURAIR UNIVERSITY College of Computing CSC 209 JAVA I week 3- Control Statements: Part I Objectives: To use the if and if...else selection statements to choose among alternative actions. To use the
More information2.8. Decision Making: Equality and Relational Operators
Page 1 of 6 [Page 56] 2.8. Decision Making: Equality and Relational Operators A condition is an expression that can be either true or false. This section introduces a simple version of Java's if statement
More information16. Give a detailed algorithm for making a peanut butter and jelly sandwich.
COSC120FinalExamReview2010 1. NamethetwotheoreticalmachinesthatCharlesBabbagedeveloped. 2. WhatwastheAntikytheraDevice? 3. Givethecodetodeclareanintegervariablecalledxandthenassignitthe number10. 4. Givethecodetoprintout
More informationIntroduction to Java Applications
2 What s in a name? that which we call a rose By any other name would smell as sweet. William Shakespeare When faced with a decision, I always ask, What would be the most fun? Peggy Walker Take some more
More informationC212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.
C212 Early Evaluation Exam Mon Feb 10 2014 Name: Please provide brief (common sense) justifications with your answers below. 1. What is the type (and value) of this expression: 5 * (7 + 4 / 2) 2. What
More informationObject Oriented Programming. Java-Lecture 1
Object Oriented Programming Java-Lecture 1 Standard output System.out is known as the standard output object Methods to display text onto the standard output System.out.print prints text onto the screen
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 informationLoops. Repeat after me
Loops Repeat after me Loops A loop is a control structure in which a statement or set of statements execute repeatedly How many times the statements repeat is determined by the value of a control variable,
More informationIntroduction to Computer Science Unit 3. Programs
Introduction to Computer Science Unit 3. Programs This section must be updated to work with repl.it Programs 1 to 4 require you to use the mod, %, operator. 1. Let the user enter an integer. Your program
More informationBuilding Java Programs
Building Java Programs Chapter 5 Lecture 5-1: while Loops, Fencepost Loops, and Sentinel Loops reading: 4.1, 5.1 self-check: Ch. 4 #2; Ch. 5 # 1-10 exercises: Ch. 4 #2, 4, 5, 8; Ch. 5 # 1-2 Copyright 2009
More information1. A company has vans to transport goods from factory to various shops. These vans fall into two categories: 50 items 150 items
If..Else Statement Exercises 1. A company has vans to transport goods from factory to various shops. These vans fall into two categories: Category Normal Duty Van Heavy Duty Van Capacity 50 items 150 items
More informationSCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming
s SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177 Programming Time allowed: THREE hours: Answer: ALL questions Items permitted: Items supplied: There is
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 informationChapter 4: Control structures. Repetition
Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition
More informationChapter 3 Lab Decision Structures
Chapter 3 Lab Decision Structures Lab Objectives Be able to construct boolean expressions to evaluate a given condition Be able to compare String objects Be able to use a flag Be able to construct if and
More informationJava Programming Language. 0 A history
Java Programming Language 0 A history How java works What you ll do in Java JVM API Java Features 0Platform Independence. 0Object Oriented. 0Compiler/Interpreter 0 Good Performance 0Robust. 0Security 0
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 informationCS111: PROGRAMMING LANGUAGE II
CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1(c): Java Basics (II) Lecture Contents Java basics (part II) Conditions Loops Methods Conditions & Branching Conditional Statements A
More informationAP COMPUTER SCIENCE A
AP COMPUTER SCIENCE A CONTROL FLOW Aug 28 2017 Week 2 http://apcs.cold.rocks 1 More operators! not!= not equals to % remainder! Goes ahead of boolean!= is used just like == % is used just like / http://apcs.cold.rocks
More 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 informationChapter 3. Selections
Chapter 3 Selections 1 Outline 1. Flow of Control 2. Conditional Statements 3. The if Statement 4. The if-else Statement 5. The Conditional operator 6. The Switch Statement 7. Useful Hints 2 1. Flow of
More informationChapter 3 Selections. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.
Chapter 3 Selections Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 1 Motivations If you assigned a negative value for radius
More informationIntroduction to Computer Science Unit 2. Exercises
Introduction to Computer Science Unit 2. Exercises Note: Curly brackets { are optional if there is only one statement associated with the if (or ) statement. 1. If the user enters 82, what is 2. If the
More informationChapter 4: Control structures
Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition
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 informationArrays OBJECTIVES. In this chapter you will learn:
7 Arrays 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
More informationTask 1: Print a series of random integers between 0 and 99 until the value 77 is printed. Use the Random class to generate random numbers.
Task 1: Print a series of random integers between 0 and 99 until the value 77 is printed. Use the Random class to generate random numbers. Task 2: Print a series of random integers between 50 and 99 until
More informationSequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;
Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The
More informationExample. Write a program which sums two random integers and lets the user repeatedly enter a new answer until it is correct.
Example Write a program which sums two random integers and lets the user repeatedly enter a new answer until it is correct. 1... 2 Scanner input = new Scanner(System.in); 3 int x = (int) (Math.random()
More informationSection 2.2 Your First Program in Java: Printing a Line of Text
Chapter 2 Introduction to Java Applications Section 2.2 Your First Program in Java: Printing a Line of Text 2.2 Q1: End-of-line comments that should be ignored by the compiler are denoted using a. Two
More informationAP CS Unit 3: Control Structures Notes
AP CS Unit 3: Control Structures Notes The if and if-else Statements. These statements are called control statements because they control whether a particular block of code is executed or not. Some texts
More informationWelcome1.java // Fig. 2.1: Welcome1.java // Text-printing program.
1 Welcome1.java // Fig. 2.1: Welcome1.java // Text-printing program. public class Welcome1 // main method begins execution of Java application System.out.println( "Welcome to Java Programming!" ); } //
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 informationCOE 212 Engineering Programming. Welcome to Exam II Thursday April 21, Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F.
1 COE 212 Engineering Programming Welcome to Exam II Thursday April 21, 2016 Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam is Closed Book.
More informationControl Statements: Part 1
4 Let s all move one place on. Lewis Carroll Control Statements: Part 1 The wheel is come full circle. William Shakespeare How many apples fell on Newton s head before he took the hint! Robert Frost All
More informationWrite a program which converts all lowercase letter in a sentence to uppercase.
Write a program which converts all lowercase letter in a sentence to uppercase. For Example: 1) Consider a sentence "welcome to Java Programming!" its uppercase conversion is " WELCOME TO JAVA PROGRAMMING!"
More informationJava. Programming: Chapter Objectives. Why Is Repetition Needed? Chapter 5: Control Structures II. Program Design Including Data Structures
Chapter 5: Control Structures II Java Programming: Program Design Including Data Structures Chapter Objectives Learn about repetition (looping) control structures Explore how to construct and use count-controlled,
More informationUniversità degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M
Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models, and Applications for Distributed Systems M Control Structures Intro. Sequential execution Statements are normally executed one
More informationNew York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:
Name: New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case Instructions: KEEP TEST BOOKLET CLOSED UNTIL YOU ARE INSTRUCTED TO BEGIN. This exam is double sided (front
More informationECE 161 WEEK 4 Introduction to Programing in Java
1 ECE 161 WEEK 4 Introduction to Programing in Java 26.10.05 Prof Dr. Ziya B. Güvenç Res. Asst. Barbaros Preveze Java creator and Software Development Kit J(2S)DK is used for compiling any portion of the
More informationUniversità degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M
Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models, and Applications for Distributed Systems M tutor Isam M. Al Jawarneh, PhD student isam.aljawarneh3@unibo.it Mobile Middleware
More informationSystem.out.printf("Please, enter the value of the base : \n"); base =input.nextint();
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
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 informationClasses and Objects Miscellany: I/O, Statics, Wrappers & Packages. CMSC 202H (Honors Section) John Park
Classes and Objects Miscellany: I/O, Statics, Wrappers & Packages CMSC 202H (Honors Section) John Park Basic Input/Output Version 9/10 2 Printing to the Screen In addition to System.out.print() (and println()):
More informationAYBUKE BUYUKCAYLI KORAY OZUYAR MUSTAFA SOYLU. Week 21/02/ /02/2007 Lecture Notes: ASCII
AYBUKE BUYUKCAYLI KORAY OZUYAR MUSTAFA SOYLU Week 21/02/2007-23/02/2007 Lecture Notes: ASCII 7 bits = 128 characters 8 bits = 256characters Unicode = 16 bits Char Boolean boolean frag; flag = true; flag
More informationRepetition CSC 121 Fall 2014 Howard Rosenthal
Repetition CSC 121 Fall 2014 Howard Rosenthal Lesson Goals Learn the following three repetition methods, their similarities and differences, and how to avoid common errors when using them: while do-while
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 informationNew York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:
Name: New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case Instructions: KEEP TEST BOOKLET CLOSED UNTIL YOU ARE INSTRUCTED TO BEGIN. This exam is double sided (front
More informationCSC 1051 Data Structures and Algorithms I
Repetition CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in this
More informationThe Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016
First Name (Print): Last Name (Print): Student Number: The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II 2016 Instructor: Dr. Bowen Hui Tuesday, April 19, 2016 Time: 6:00pm
More informationITERATION WEEK 4: EXMAPLES IN CLASS
Monday Section 2 import java.util.scanner; public class W4MSection2 { ITERATION WEEK 4: EXMAPLES IN CLASS public static void main(string[] args) { Scanner input1 = new Scanner (System.in); int CircleCenterX
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 informationProgram 12 - Spring 2018
CIST 1400, Introduction to Computer Programming Programming Assignment Program 12 - Spring 2018 Overview of Program Earlier this semester, you have written programs that read and processed dates in various
More informationComputer Programming, I. Laboratory Manual. Experiment #6. Loops
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 #6
More informationComputer Programming, I. Laboratory Manual. Experiment #3. Selections
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 #3
More information1. Find the output of following java program. class MainClass { public static void main (String arg[])
1. Find the output of following java program. public static void main(string arg[]) int arr[][]=4,3,2,1; int i,j; for(i=1;i>-1;i--) for(j=1;j>-1;j--) System.out.print(arr[i][j]); 1234 The above java program
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 informationPractice Midterm 1. Problem Points Score TOTAL 50
CS 120 Software Design I Spring 2019 Practice Midterm 1 University of Wisconsin - La Crosse February 25 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages including the
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 informationCSC 1051 Data Structures and Algorithms I
Repetition CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in this
More informationPractice Midterm 1 Answer Key
CS 120 Software Design I Fall 2018 Practice Midterm 1 Answer Key University of Wisconsin - La Crosse Due Date: October 5 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages
More informationCS110: PROGRAMMING LANGUAGE I
CS110: PROGRAMMING LANGUAGE I Computer Science Department Lecture 4: Java Basics (II) A java Program 1-2 Class in file.java class keyword braces {, } delimit a class body main Method // indicates a comment.
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 informationJava Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM
Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM Let s get some practice creating programs that repeat commands inside of a loop in order to accomplish a particular task. You may
More informationOct Decision Structures cont d
Oct. 29 - Decision Structures cont d Programming Style and the if Statement Even though an if statement usually spans more than one line, it is really one statement. For instance, the following if statements
More informationWentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics
WIT COMP1000 Java Basics Java Origins Java was developed by James Gosling at Sun Microsystems in the early 1990s It was derived largely from the C++ programming language with several enhancements Java
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 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 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 informationRepe$$on CSC 121 Fall 2015 Howard Rosenthal
Repe$$on CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Learn the following three repetition methods, their similarities and differences, and how to avoid common errors when using them: while do-while
More informationSelec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal
Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program
More information1 class Lecture4 { 2 3 "Loops" / References 8 [1] Ch. 5 in YDL 9 / Zheng-Liang Lu Java Programming 125 / 207
1 class Lecture4 { 2 3 "Loops" 4 5 } 6 7 / References 8 [1] Ch. 5 in YDL 9 / Zheng-Liang Lu Java Programming 125 / 207 Loops A loop can be used to make a program execute statements repeatedly without having
More informationCS Week 5. Jim Williams, PhD
CS 200 - Week 5 Jim Williams, PhD The Study Cycle Check Am I using study methods that are effective? Do I understand the material enough to teach it to others? http://students.lsu.edu/academicsuccess/studying/strategies/tests/studying
More informationAssignment Checklist. Prelab Activities. Lab Exercises. Labs Provided by Instructor. Postlab Activities. Section:
7 Arrays 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
More informationIST 297D Introduction to Application Programming Chapter 4 Problem Set. Name:
IST 297D Introduction to Application Programming Chapter 4 Problem Set Name: 1. Write a Java program to compute the value of an investment over a number of years. Prompt the user to enter the amount of
More informationAlgorithms and Java basics: pseudocode, variables, assignment, and interactive programs
Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs CSC 1051 Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova
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 informationMethod OverLoading printf method Arrays Declaring and Using Arrays Arrays of Objects Array as Parameters
Outline Method OverLoading printf method Arrays Declaring and Using Arrays Arrays of Objects Array as Parameters Variable Length Parameter Lists split() Method from String Class Integer & Double Wrapper
More informationAssoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Java application A computer program that executes when you use the java command to launch the Java Virtual Machine
More informationSupplementary Test 1
Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2009 Supplementary Test 1 Question
More informationAlgorithms in everyday life. Algorithms. Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs
Data and Algorithms Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs Algorithms in everyday life CSC 1051 Algorithms and Data Structures I Dr. Mary-Angela Papalaskari
More informationCSCI 1101 Winter 2017 Laboratory No Submission deadline is p.m. (5 minutes to midnight) on Saturday, February 4th, 2017.
CSCI 1101 Winter 2017 Laboratory No. 3 This lab is a continuation of the concepts of object-oriented programming, specifically the use of static variables and static methods, and object interactions. If
More informationCS 161. SAMPLE FINAL Fall 2014
CS 161 SAMPLE FINAL Fall 2014 1. What are the three parts of a loop? How are those three things organized in a while loop? How are they organized in a for loop? 2. Write the code to declare MyStuff to
More informationCS1150 Principles of Computer Science Arrays
CS1150 Principles of Computer Science Arrays Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Opening Problem Read one hundred numbers, compute their
More informationDate: Dr. Essam Halim
Assignment (1) Date: 11-2-2013 Dr. Essam Halim Part 1: Chapter 2 Elementary Programming 1 Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in); What method do you use
More informationCOSC 1010 Introduction to Computer Programming
COSC 1010 Introduction to Computer Programming Exam 1, Spring 2016 Exam Duration: Sixty (60) Minutes The exam has three parts: Multiple Choice (17 points), Short Answer (30 points) and Programming (53
More informationCS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009
CS 102 - Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009 What is your name?: There are two sections: I. True/False..................... 60 points; ( 30 questions, 2 points each) II.
More informationLecture 6. Drinking. Nested if. Nested if s reprise. The boolean data type. More complex selection statements: switch. Examples.
// Simple program to show how an if- statement works. import java.io.*; Lecture 6 class If { static BufferedReader keyboard = new BufferedReader ( new InputStreamReader( System.in)); public static void
More information