ImageVerifierCode 换一换
格式:DOCX , 页数:22 ,大小:359.05KB ,
资源ID:12367829      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/12367829.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Java Exercises JAVA练习题.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Java Exercises JAVA练习题.docx

1、Java Exercises JAVA练习题1.5 Input and OutputExercises 1Write a program MaxMin.java that reads in integers (as many as the user enters) from standard input and prints out the maximum and minimum alues.2Modify your program from the previous exercise to insist that the integers must be positive (by promp

2、ting the user to enter positive integers whenever the value entered is not positive).3Write a program Stats.java that takes an integer N from the command line, reads N double values from standard input, and prints their mean (average value) and standard deviation (square root of the sum of the squar

3、es of their differences from the average, divided by N - 1).4Extend your program from the previous exercise to create a filter that prints all the values that are further than 1.5 standard deviations from the mean.5Write a program LongestRun.java that reads in a sequence of integers and prints out b

4、oth the integer that appears in a longest consecutive run and the length of the run. For example, if the input is 1 2 2 1 5 1 1 7 7 7 7 1 1, then your program should print Longest run: 4 consecutive 7s.6Write a filter that reads in a sequence of integers and prints out the integers, removing repeate

5、d values that appear consecutively. For example, if the input is 1 2 2 1 5 1 1 7 7 7 7 1 1 1 1 1 1 1 1 1, your program should print out 1 2 1 5 1 7 1.7Write a program that takes a command-line argument N, reads in N-1 distinct integers between 1 and N, and determines the missing value.8Write a progr

6、am GeometricMean.java that reads in positive real numbers from standard input and prints out their geometric mean. The geometric meanof N positive numbers x1, x2, ., xN is (x1 * x2 * . * xN)1/N. Write a program HarmonicMean.java that reads in positive real numbers from standard input and prints out

7、their harmonic mean. The harmonic mean of N positive numbers x1, x2, ., xN is (1/x1 + 1/x2 + . + 1/xN) / (1 / N).Hint: for the geometric mean, consider taking logs to avoid overflow.9Suppose that the file input.txt contains the two strings F and F. What does the following command do (see Exercises 1

8、.2.35)? Here is the Java program Dragon.java.java Dragon input.txt | java Dragon | java Dragon 10Write a filter TenPerLine.java that takes a sequence of integers between 0 and 99 and prints 10 integers per line, with columns aligned. Then write a program RandomIntSeq that takes two command-line argu

9、ments M and N and outputs N random integers between 0 and M-1. Test your programs with the command java RandomIntSeq 200 100 | java TenPerLine.11Write a program WordCount.java that reads in text from standard input and prints out the number of words in the text. For the purpose of this exercise, a w

10、ord is a sequence of non-whitespace characters that is surrounded by whitespace.12Write a program that reads in lines from standard input with each line containing a name and two integers and then uses printf() to print a table with a column of the names, the integers, and the result of dividing the

11、 first by the second, accurate to three decimal places. You could use a program like this to tabulate batting averages for baseball players or grades for students.13Which of the following require saving all the values from standard input (in an array, say), and which could be implemented as a filter

12、 using only a fixed number of variables? For each, the input comes from standard input and consists of N real numbers between 0 and 1.Print the maximum and minimum numbers.Print the kth smallest value.Print the sum of the squares of the numbers.Print the average of the N numbers.Print the percentage

13、 of numbers greater than the average.Print the N numbers in increasing order.Print the N numbers in random order.14Write a program that prints a table of the monthly payments, remaining principal, and interest paid for a loan, taking three numbers as command-line arguments: the number of years, the

14、principal, and the interest rate (see Exercise 1.2.24).15Write a program Closest.java that takes three command-line arguments x, y, z, reads from standard input a sequence of point coordinates (xi, yi, zi), and prints the coordinates of the point closest to (x, y, z). Recall that the square of the d

15、istance between (x, y, z) and (xi, yi, zi) is (x - xi)2 + (y - yi)2 + (z - zi)2. For efficiency, do not use Math.sqrt() or Math.pow().16Given the positions and masses of a sequence of objects, write a progrm to compute their center-of-mass or centroid. The centroid is the average position of the N o

16、bjects, weighted by msass. If the positions and masses are given by (xi, yi, mi), then the centroid (x, y, m) is given by:m = m1 + m2 + . + mNx = (m1x1 + . + mnxN) / my = (m1y1 + . + mnyN) / mWrite a program Centroid.java that reads in a sequence of positions and masses (xi, yi, mi) from standard in

17、put and prints out their center of mass (x,y, m). Hint: model your program after Average.java.17Write a program SignalAnalyzer.java that reads in a sequence of real numbers between -1 and 1 and prints out their average magnitude, average power, and the number of zero crossings. The average magnitude

18、 is the average of the absolute values of the data values. The average power is the average of the squares of the data values. The number of zero crossings is the number of times a data value transitions from a strictly negative number to a strictly positive number, or vice versa. These three statis

19、tics are widely used to analyze digital signals.18Write a program CheckerBoard.java that takes a command-line argument N and plots an N-by-N checkerboard with red and black squares. Color the lower left square red.19Write a program that takes as command-line arguments an integer N and a double value

20、 p (between 0 and 1), plots N equally spaced points of size on the circumference of a circle, and then, with probability p for each pair of points, draws a gray line connecting them.20Write code to draw hearts, spades, clubs, and diamonds. To draw a heart, draw a diamond, then attach two semicircles

21、 to the upper left and upper right sides.21Write a program Rose.java that takes a command-line argument N and plots a rose with N petals (if N is odd) or 2N petals (if N is even) by plotting the polar coordinates (r, ) of the function r = sin(N ) for ranging from 0 to 2 radians. Below is the desired

22、 output for N = 4, 7, and 8.22Write a program Banner.java that takes a string s from the command line and display it in banner style on the screen, moving from left to right and wrapping back to the beginning of the string as the end is reached. Add a second command-line argument to control the spee

23、d.23Modify PlayThatTune.java to take additional command-line arguments that control the volume (multiply each sample value by the volume) and the tempo (multiply each notes duration by the tempo).24Write a program that takes the name of a .wav file and a playback rate r as command-line arguments and

24、 plays the file at the given rate. First, useStdAudio.read() to read the file into an array a. If r = 1, just play a; otherwise create a new array b of approximate size r times a.length. If r 1, populate b by interpolating from the original. Then play b.25Write programs that uses StdDraw to create e

25、ach of the following designs.2627Write a program Circles.java that draws filled circles of random size at random positions in the unit square, producing images like those below. Your program should take four command-line arguments: the number of circles, the probability that each circle is black, th

26、e minimum radius, and the maximum radius.Creative Exercises28Visualizing audio. Modify PlayThatTune.java to send the values played to standard drawing, so that you can watch the sound waves as they are played. You will have to experiment with plotting multiple curves in the drawing canvas to synchro

27、nize the sound and the picture.29Statistical polling. When collecting statistical data for certain political polls, it is very important to obtain an unbiased sample of registered voters. Assume that you have a file with N registered voters, one per line. Write a filter that prints out a random samp

28、le of size M (see Program 1.4.1).30Terrain analysis. Suppose that a terrain is represented by a two-dimensional grid of elevation values (in meters). A peak is a grid point whose four neighboring cells (left, right, up, and down) have strictly lower elevation values. Write a program Peaks.java that

29、reads a terrain from standard input and then computes and prints the number of peaks in the terrain.31Histogram. Suppose that the standard input stream is a sequence of double values. Write a program that takes an integer N and two double values l and r from the command line and uses StdDraw to plot

30、 a histogram of the count of the numbers in the standard input stream that fall in each of the N intervals defined by dividing (l , r) into N equal-sized intervals.32Spirographs. Write a program Spirograph.java that takes three command-line arguments R, r, and a and draws the resulting spirograph. A

31、 spirograph(technically, an epicycloid) is a curve formed by rolling a circle of radius r around a larger fixed circle or radius R. If the pen offset from the center of the rolling circle is (r+a), then the equation of the resulting curve at time t is given byx(t) = (R+r)*cos(t) - (r+a)*cos(R+r)/r)*

32、t)y(t) = (R+r)*sin(t) - (r+a)*sin(R+r)/r)*t)Such curves were popularized by a best-selling toy that contains discs with gear teeth on the edges and small holes that you could put a pen in to trace spirographs.For a dramatic 3d effect, draw a circular image, e.g., earth.gif instead of a dot, and show it rotating over time. Heres a picture of the resulting spirographwhen R = 180, r = 40, and a = 15.33Clock. Write a program Clock.java that displays an animation

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1