java_开发实战经典_第四章课后习题答案_完整版.doc
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
floatmax = score[0];
for(inti=0; i<score.length; i++){
if(max<score[i]){
max = score[i];
}
}
System.out.printin (”最分为:n+max);
}
}
第八题
public classFour08 {
public static voidmain(String[] args){
switch(Array[i] ) {
case1:{
nl++;
break;
}
case2:{
n2 + +;
break;
}
case3:{
n3 + + ;
break;
}
case4:{
n4++;
break;
}
case5:{
n5++;
break;
}
case6:{
n6++;
break;
}
case7:{
n7 + + ;
}
}
第二题
public static voidmain(String[]args){
inta[]={1,2,3,4,5.6,7,8,9,10,11};
int0=0,e=0;
for(inti=0 ;•丄ength; i++){
if(a[i]%2==0){
e++;
}else{
o++;
}
}
System,out.printIn("奇数个数为:”+o+”\t” + ”偶数个数为:”+e);
}
}
第三题
public classFour03 {
public static voidmain(String[]args){
intoldArr [ ] = {1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,51;
intnewArr[]=new int[16];
for(inti=0zj=0;i<oldArr•length; i++) {if(oldArr[i]!=0){
init(temp);
print(temp);
reserve(temp);
System.out.printIn();
print(temp);
)
public static voidinit(intx[]){
for(inti=0; i<x.length; i++){
X [i]= i;
}
}
public static voe8:{
doublesum = 0;
doublek[]=new double[a];
for(inti=l; i<=4; i++){
k [i-1 ] = sU27? (i);
}
for(intj=0;j<k.length;j++){
sum = sum+k[j];
}
Sys tem.out.pri nt In (”总数为:fl+sum);
head =
for(inti=0; i<x.length/2; i + + ) {inttemp =x[foot];
x[foot] = x[head];
x[head] = temp;
foot++;
head——;
}
}else{
foot = x.length/2;
head = foot ;
for(inti=0; i<x.length/2+1; i++){inttemp = x[foot];
public static voidmain(String[]args){
intArray[] = {1,2,3,4,5,6,7,8,9,10,11};
intm =max(Array);
Sys tem.out.pri nt In(”最大值为:11+m);
inta =min(Array);
System.out.printin(”最小值为:n+a);
flag =true;
)
if(flag){
System.out・println ( “YES,止匕数组屮存在元索”+c);
)else{
System,out.printin (nN0,此数组中不存在元素”+c);
}
}
)
第六题
public classFour06 {
public static voidmain(String[]args){inttemp[] =new int[10];
x [foot] = x[head];
x[head] = temp;
head--;
foot++;
第七题
public classFour07 {
public static voidmain(String args[]){
floatscore[] = {90f,87f,78f,67f,93f,79f,82f,84f,71f,86f};
for(inti=0; i<x.length; i++){
System.out.printIn(x[i]+n>n);
}
}
public static voidreserve(intx[]){
intfoot =0;
inthead = 0;
if(x.length%2 == 0){
foot = x.length/2;
newArr[j]=oldArr[i];
j++;
for(inti=0; i<newArr•length; i++){
//必须要写这个if语句,因为newArr多余的空间默认值为0if(newArr[i]!=0)
System.out.print(newArr[i]+n n);
第四题
public classFour04 {
inta =5;
intb = 100;
search(a,Array);
search(b,Array);
}
public static voidsearch(intc,inttemp[]){booleanflag =false;
for(inti=0;emp>length; i++){
if(c == temp[i]){
intArray [] = {lz2,lz3,4z6,5z4,3,2,0z9z8z
7, 6, 5, 4,3, 5, 6,7,8, 9,0, 9,8,2, 1,3,4, };
intnl=0,n2=0zn3=0zn4=0zn5=0zn6=0zn7=0zn8=0zn9=0zn0=0;
for(inti=0; i<Array•length; i++){
intsum =0;
for(inti=0; i<temp.length; i++){
sum = sum +temp[i];
}
returnsum ;
}
}
第五题
public classFour05 {
public static voidmain(String[]args){
intArray []= {1,2,3,4,5,6,7,8,9,10,11};
第一题
public classFourOl {
public static doublesum(inta){
doublesum =1;
for(inti=l; i<=a;i++){
sum = sum*i;
}
returnsum;
}
public static voidmain(String[]args){
inta=4;
ints =sum(Array);
System,out.printin(”,总数为:*'+s);
}
public static intmax(inttemp[]){
intz = temp[0];
for(inti=0;emp<length; i++){
if(z<temp[i]){
z=temp[i];
}
}
returnz;
}
public static int min(inttemp[]){
intz=temp[0];
for(inti=0; i<temp.length; i++){
if(z>temp[i]){ z=temp[i];
}
}
returnz ;
}
public static intsum(inttemp[]){
for(inti=0; i<score.length; i++){
if(max<score[i]){
max = score[i];
}
}
System.out.printin (”最分为:n+max);
}
}
第八题
public classFour08 {
public static voidmain(String[] args){
switch(Array[i] ) {
case1:{
nl++;
break;
}
case2:{
n2 + +;
break;
}
case3:{
n3 + + ;
break;
}
case4:{
n4++;
break;
}
case5:{
n5++;
break;
}
case6:{
n6++;
break;
}
case7:{
n7 + + ;
}
}
第二题
public static voidmain(String[]args){
inta[]={1,2,3,4,5.6,7,8,9,10,11};
int0=0,e=0;
for(inti=0 ;•丄ength; i++){
if(a[i]%2==0){
e++;
}else{
o++;
}
}
System,out.printIn("奇数个数为:”+o+”\t” + ”偶数个数为:”+e);
}
}
第三题
public classFour03 {
public static voidmain(String[]args){
intoldArr [ ] = {1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,51;
intnewArr[]=new int[16];
for(inti=0zj=0;i<oldArr•length; i++) {if(oldArr[i]!=0){
init(temp);
print(temp);
reserve(temp);
System.out.printIn();
print(temp);
)
public static voidinit(intx[]){
for(inti=0; i<x.length; i++){
X [i]= i;
}
}
public static voe8:{
doublesum = 0;
doublek[]=new double[a];
for(inti=l; i<=4; i++){
k [i-1 ] = sU27? (i);
}
for(intj=0;j<k.length;j++){
sum = sum+k[j];
}
Sys tem.out.pri nt In (”总数为:fl+sum);
head =
for(inti=0; i<x.length/2; i + + ) {inttemp =x[foot];
x[foot] = x[head];
x[head] = temp;
foot++;
head——;
}
}else{
foot = x.length/2;
head = foot ;
for(inti=0; i<x.length/2+1; i++){inttemp = x[foot];
public static voidmain(String[]args){
intArray[] = {1,2,3,4,5,6,7,8,9,10,11};
intm =max(Array);
Sys tem.out.pri nt In(”最大值为:11+m);
inta =min(Array);
System.out.printin(”最小值为:n+a);
flag =true;
)
if(flag){
System.out・println ( “YES,止匕数组屮存在元索”+c);
)else{
System,out.printin (nN0,此数组中不存在元素”+c);
}
}
)
第六题
public classFour06 {
public static voidmain(String[]args){inttemp[] =new int[10];
x [foot] = x[head];
x[head] = temp;
head--;
foot++;
第七题
public classFour07 {
public static voidmain(String args[]){
floatscore[] = {90f,87f,78f,67f,93f,79f,82f,84f,71f,86f};
for(inti=0; i<x.length; i++){
System.out.printIn(x[i]+n>n);
}
}
public static voidreserve(intx[]){
intfoot =0;
inthead = 0;
if(x.length%2 == 0){
foot = x.length/2;
newArr[j]=oldArr[i];
j++;
for(inti=0; i<newArr•length; i++){
//必须要写这个if语句,因为newArr多余的空间默认值为0if(newArr[i]!=0)
System.out.print(newArr[i]+n n);
第四题
public classFour04 {
inta =5;
intb = 100;
search(a,Array);
search(b,Array);
}
public static voidsearch(intc,inttemp[]){booleanflag =false;
for(inti=0;emp>length; i++){
if(c == temp[i]){
intArray [] = {lz2,lz3,4z6,5z4,3,2,0z9z8z
7, 6, 5, 4,3, 5, 6,7,8, 9,0, 9,8,2, 1,3,4, };
intnl=0,n2=0zn3=0zn4=0zn5=0zn6=0zn7=0zn8=0zn9=0zn0=0;
for(inti=0; i<Array•length; i++){
intsum =0;
for(inti=0; i<temp.length; i++){
sum = sum +temp[i];
}
returnsum ;
}
}
第五题
public classFour05 {
public static voidmain(String[]args){
intArray []= {1,2,3,4,5,6,7,8,9,10,11};
第一题
public classFourOl {
public static doublesum(inta){
doublesum =1;
for(inti=l; i<=a;i++){
sum = sum*i;
}
returnsum;
}
public static voidmain(String[]args){
inta=4;
ints =sum(Array);
System,out.printin(”,总数为:*'+s);
}
public static intmax(inttemp[]){
intz = temp[0];
for(inti=0;emp<length; i++){
if(z<temp[i]){
z=temp[i];
}
}
returnz;
}
public static int min(inttemp[]){
intz=temp[0];
for(inti=0; i<temp.length; i++){
if(z>temp[i]){ z=temp[i];
}
}
returnz ;
}
public static intsum(inttemp[]){