`
guoyiqi
  • 浏览: 1001847 次
社区版块
存档分类
最新评论

java循环

    博客分类:
  • java
 
阅读更多

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.

分享到:
评论

相关推荐

    Java 循环语句练习题.docx

    这个 Java 循环语句练习题文档旨在帮助初学者熟悉 Java 语言的循环语句,包括 for 循环、while 循环、do-while 循环等。通过练习题的解答,读者可以熟悉 Java 语言的基本语法和循环语句的使用方法。 一、for 循环...

    java 循环语句练习

    本文档对 Java 循环语句的练习题进行了整理,包含了多种循环语句的使用场景,例如 for 循环、嵌套循环等。通过实践这些练习题,可以更好地理解和掌握 Java 语言中的循环语句。 一、循环语句的基本概念 循环语句是...

    Java循环技巧大全

    ### Java循环技巧大全 在Java编程中,循环结构是实现重复执行特定代码块的基本方法之一。本文将深入探讨Java中的循环技巧,特别是如何利用不同类型的循环控制语句来优化程序性能,提高代码可读性和可维护性。 ####...

    Java循环语句学习例子源码

    这里,我们有一个名为"Java循环语句学习例子源码程序"的资源,它提供了一个实际的Visita风格登录界面的实现,通过Java技术进行了精致的重构。这个程序是一个很好的学习平台,可以帮助开发者深入理解Java中的循环语句...

    java循环结构学习教案.pptx

    Java循环结构学习教案 本节课程主要讲解Java中的循环结构,包括while循环、do-while循环和for循环。通过学习本节课程,学生将能够理解循环的含义,学会使用while循环、do-while循环和for循环结构,并能够使用调试...

    练习Java循环的一些源代码例子

    以下是对Java循环的一些详细知识点的讲解: 1. **for循环**:Java中的for循环是最常见的循环类型,通常用于已知循环次数的情况。它的语法结构为: ``` for (初始化; 条件; 更新) { // 循环体 } ``` 例如,...

    Java循环结构习题.pdf

    Java循环结构习题.pdf Java循环结构习题.pdf 是一个 Java 编程习题集,涵盖了循环结构、素数、绝对素数等概念。下面是对每个习题的详细解释和知识点总结: A. 求 1 到 100 以内的素数 * 知识点:循环结构、素数的...

    Java循环练习

    ### Java循环练习知识点详解 #### 1. 打印出100~999之间的所有“水仙花数” **知识点概述:** - **水仙花数定义**:一个三位数,其各位数字的立方和等于该数本身。 - **循环结构**:使用三层嵌套循环来遍历所有...

    java循环队列的分析和实例介绍.pdf

    ### Java循环队列的深入解析与实践应用 #### 循环队列概念解析 循环队列,作为一种高效的数据结构,广泛应用于计算机科学中,尤其是在Java编程语言中,它以其独特的性能优势,在各种算法和系统设计中占据了...

    java循环Map java迭代Map

    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

    Java循环解析xml文档,放在hashtable里,方便安装标签名取值

    17.java循环语句.zip

    17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java...

    Java循环练习题

    Java循环练习题 本练习题涵盖了 Java 语言中循环结构的应用,包括 for 循环、while 循环和 do-while 循环等,旨在帮助程序员熟练掌握 Java 语言的循环结构,提高编程能力。 一、山上有一口缸可以装 50 升水,现在...

    java 循环算法 练习题

    本练习题旨在帮助提升你对Java循环算法的理解和应用能力。 循环是程序设计中的基本构造之一,它允许我们重复执行一段代码,直到满足某个特定条件为止。Java提供了多种类型的循环结构,包括for、while和do-while循环...

    java循环结构

    Java语言中的循环结构是编程中不可或缺的一部分,它允许程序重复执行一段代码,直到满足特定条件为止。循环结构在处理重复任务、数组遍历、数据处理等场景中非常常见。这里我们将详细探讨Java中的几种主要循环结构,...

    java循环结构.ppt

    Java循环结构 Java中的循环结构是指在某些条件下重复执行代码的机制。循环结构可以分为四种:while循环、do-while循环、for循环和switch循环。 一、while循环 while循环是最基本的循环结构。它的特点是先判断循环...

    java循环语句(典型的循环语句)

    Java是一种广泛使用的面向对象的编程语言,其循环语句是编程中最基础且重要的部分,用于重复执行一段代码,直到满足特定条件为止。本篇将详细讲解Java中的典型循环语句,包括数组循环和遍历循环。 1. **for循环**:...

    java 循环录入会员积分

    一个简单的会员积分录入循环模式,供初学者借鉴。

    JAVA循环结构

    JAVA循环结构

    Java循环作业.zip

    在这个"Java循环作业.zip"文件中,可能包含了不同类型的循环练习,旨在帮助初学者巩固这方面的知识。下面我们将深入探讨Java中的循环结构及其相关知识点。 1. **for循环**:Java的for循环是最常见的循环结构之一,...

Global site tag (gtag.js) - Google Analytics