Computer Science, Claremont McKenna College
CS51.2 - Introduction to Computer Science, Fall 2014
Problem Set 2 Due: 11:55 AM, Sept 18, 2014
General Instructions
Please carefully read and follow the directions exactly for each problem. Files and classes should be
named exactly as directed in the problem (including capitalization!) as this will help with grading.
You should create your programs using your preferred text-editor, the Eclipse text editor, or jGrasp. Do
not use a word processor such as Microsoft Word, WordPad, Google Docs, Apple’s Pages, etc...
Your programs should be formatted in a way that’s readable. In other words, indent appropriately, use
informative names for variables, etc… If you are uncertain about what is a readable style, look at the
examples from class as a starting point for a reasonable coding style.
This problem set assumes you have installed Java and an IDE (Eclipse or jGrasp) on your system. Please
see the course web page on Sakai for installation instructions.
Your programs should compile and run without errors. Please do not submit programs that do not
compile! It’s better to submit partial implementation that compiles as oppose to implementations that do
not compile.
At the top of each file you submit, you should put your name and your email as comments.
This homework set should be submitted via Sakai using the Assignment Menu option (on the left pane).
You should only submit the requested “.java” files. Do not submit “.class” files or Eclipse-specific
project files. Finally, please do not submit files using Sakai’s Dropbox Menu.
Turn in the following file(s):
MilesToFeet.java
DollarsToBills.java
DollarFigure.java
FactorialLoop.java
Problem 1
In this warmup problem, write a program in MilesToFeet.java that converts a specified number of
miles into number of feet. Declare a variable named numMiles that’s initialized to 11.3. Declare
another variable named numFeet. Think about what type these variables should be. You should then
perform the conversion from miles to feet and assign the value to numFeet. Print something informative
such as “X miles is Y feet.”
Problem 2
Write a program in DollarsToBills.java that converts a specified number of dollars into the
number of twenty dollar bills, the number of ten dollar bills, the number of five dollar bills, and the
number of one dollar bills. In doing this conversion, you should first maximize the number of twenty
dollar bills, then maximize the number of ten dollar bills, etc… Declare a variable named nDollars
and assign 99 to it. Declare a variable named nTwenty to hold the number of twenty dollar bills,
nTens to hold the number of ten dollar bills, nFives to hold the number of five dollar bills and nOnes
to hold the number of one dollar bills. Think about what type these variables should be. (You may use
other variables as needed.) Print out the conversion with meaningful annotation such “99 dollars is equal
to 4 twenties, 1 tens, …”
Problem 3
In a file named DollarFigure.java , write a program that uses for loops to produce the following:
$$$$$$$**************$$$$$$$
**$$$$$$************$$$$$$**
****$$$$$**********$$$$$****
******$$$$********$$$$******
********$$$******$$$********
**********$$****$$**********
************$**$************
Problem 4
Using nested for loops, write a program in FactorialLoop.java that calculates and then prints out
the factorial of the numbers from 3 to 9 (inclusive). Print out the factorials in the following form:
3 factorial is equal to 6
4 factorial is equal to 24
etc…
Consider using a variable to track the intermediate “running” factorial result as the factorial is being
calculated in a loop.
- 浏览: 1010450 次
文章分类
最新评论
-
18335864773:
很多公司项目 都在使用pageoffice 来操作word,e ...
用java生成word文档 -
Gozs_cs_dn:
请问下博主, 怎样将sitemesh3.xsd绑定 sitem ...
SiteMesh3配置 -
Rose_06:
springside4.0quick-start.bat报错原因 -
ilemma:
我也是刚参见工作啊,经理让自学这个,有些东西不太懂,能不能发个 ...
Apache Shiro在Web中的应用 -
shanbangyou:
你废了
程序员上班打酱油的方法
- ch01.pdf (8 MB)
- 下载次数: 0
发表评论
-
java冒泡排序对布尔类型进行排序
2015-12-11 23:06 647QQ 928900200 程序代写 java不能对 ... -
java星球机器人建模UML
2014-10-06 22:29 398Your task is to design and imp ... -
代写java程序qq:928900200
2014-06-18 12:46 3学校为全面提升学校教学质量,提高管理水平,决定开发一套小型成 ... -
StringTokenizer类的使用
2013-12-13 15:15 391StringTokenizer是一个用来分隔String的应 ... -
销售管理需求分析
2013-07-03 08:18 5041. 概述 目前,销售管理在企业管理中 ... -
基于jsp+servlet+jdbc的销售管理
2013-07-02 16:32 7源码http://apenny.taobao.com 1 ... -
Java获取请求客户端的真实IP地址
2012-05-07 16:40 908通常通过request.getRemoteAd ... -
java读取excel
2012-03-30 16:56 464import org.apache.poi.hssf.user ... -
基于Myeclipse9.1的spring3.1MVC开发搭建
2011-10-01 14:27 2040(1)配置基础装备。每个符合Java EE规范的web应用程 ... -
myeclipse 9.1 破解成功
2011-09-28 18:06 72289.0 的注册机在windows下 ... -
myeclipse9.1下载及破解方法-破解版
2011-09-26 11:17 21497MyEclipse 9.1 下载 注册 破 ... -
JDBC4.1更新了两个新特性
2011-05-20 10:23 10131. Connection,ResultSet 和 State ... -
Java replaceAll的陷阱之括弧
2011-05-09 16:26 4506大家都知道,replaceAll这个东西支持regular e ... -
Archive for 四月, 2011JavaEye被逼改名ItEye
2011-04-02 08:50 611Oracle挥舞法律大棒 JavaEy ... -
test
2011-04-02 08:34 430<script type="text/Java ... -
开源文档学习
2011-03-31 17:29 539http://www.family168.com -
myeclipse 8.6 M1 注册码
2011-03-31 10:13 1039Subscriber:MaYong Subscription ... -
java web 开源框架
2011-03-31 09:49 1049WebWork WebWork是由O ... -
js 画线
2010-06-06 12:42 3153本例子用wz_jsgraphics.js进行画矢量图,兼容多浏 ... -
google 谷歌 吃豆人 pacman
2010-05-26 12:12 1283原则上Google的Doodle只有 ...
相关推荐
这个 Java 循环语句练习题文档旨在帮助初学者熟悉 Java 语言的循环语句,包括 for 循环、while 循环、do-while 循环等。通过练习题的解答,读者可以熟悉 Java 语言的基本语法和循环语句的使用方法。 一、for 循环...
本文档对 Java 循环语句的练习题进行了整理,包含了多种循环语句的使用场景,例如 for 循环、嵌套循环等。通过实践这些练习题,可以更好地理解和掌握 Java 语言中的循环语句。 一、循环语句的基本概念 循环语句是...
### Java循环技巧大全 在Java编程中,循环结构是实现重复执行特定代码块的基本方法之一。本文将深入探讨Java中的循环技巧,特别是如何利用不同类型的循环控制语句来优化程序性能,提高代码可读性和可维护性。 ####...
这里,我们有一个名为"Java循环语句学习例子源码程序"的资源,它提供了一个实际的Visita风格登录界面的实现,通过Java技术进行了精致的重构。这个程序是一个很好的学习平台,可以帮助开发者深入理解Java中的循环语句...
Java循环结构学习教案 本节课程主要讲解Java中的循环结构,包括while循环、do-while循环和for循环。通过学习本节课程,学生将能够理解循环的含义,学会使用while循环、do-while循环和for循环结构,并能够使用调试...
以下是对Java循环的一些详细知识点的讲解: 1. **for循环**:Java中的for循环是最常见的循环类型,通常用于已知循环次数的情况。它的语法结构为: ``` for (初始化; 条件; 更新) { // 循环体 } ``` 例如,...
### Java循环练习知识点详解 #### 1. 打印出100~999之间的所有“水仙花数” **知识点概述:** - **水仙花数定义**:一个三位数,其各位数字的立方和等于该数本身。 - **循环结构**:使用三层嵌套循环来遍历所有...
### Java循环队列的深入解析与实践应用 #### 循环队列概念解析 循环队列,作为一种高效的数据结构,广泛应用于计算机科学中,尤其是在Java编程语言中,它以其独特的性能优势,在各种算法和系统设计中占据了...
Map a = new HashMap(); //方法一 Iterator it = a.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry) it.next(); System.out.println(pairs.getValue()); ...//以下方法需要jdk5以上...
Java循环解析xml文档,放在hashtable里,方便安装标签名取值
17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java...
Java循环练习题 本练习题涵盖了 Java 语言中循环结构的应用,包括 for 循环、while 循环和 do-while 循环等,旨在帮助程序员熟练掌握 Java 语言的循环结构,提高编程能力。 一、山上有一口缸可以装 50 升水,现在...
本练习题旨在帮助提升你对Java循环算法的理解和应用能力。 循环是程序设计中的基本构造之一,它允许我们重复执行一段代码,直到满足某个特定条件为止。Java提供了多种类型的循环结构,包括for、while和do-while循环...
Java语言中的循环结构是编程中不可或缺的一部分,它允许程序重复执行一段代码,直到满足特定条件为止。循环结构在处理重复任务、数组遍历、数据处理等场景中非常常见。这里我们将详细探讨Java中的几种主要循环结构,...
Java循环结构 Java中的循环结构是指在某些条件下重复执行代码的机制。循环结构可以分为四种:while循环、do-while循环、for循环和switch循环。 一、while循环 while循环是最基本的循环结构。它的特点是先判断循环...
Java是一种广泛使用的面向对象的编程语言,其循环语句是编程中最基础且重要的部分,用于重复执行一段代码,直到满足特定条件为止。本篇将详细讲解Java中的典型循环语句,包括数组循环和遍历循环。 1. **for循环**:...
一个简单的会员积分录入循环模式,供初学者借鉴。
JAVA循环结构
在这个"Java循环作业.zip"文件中,可能包含了不同类型的循环练习,旨在帮助初学者巩固这方面的知识。下面我们将深入探讨Java中的循环结构及其相关知识点。 1. **for循环**:Java的for循环是最常见的循环结构之一,...
java循环结构,while、for循环、do-while,及调试解决程序错误