Java语言程序设计与数据结构(基础篇)课后练习题 第八章(二)

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!

(brackets[1][2] - brackets[1][1]) * rates[2];

else if(taxableIncome<=208850)

tax=brackets[1][0] * rates[0]+

(brackets[1][1] - brackets[1][0]) * rates[1] +

(brackets[1][2] - brackets[1][1]) * rates[2] +

(brackets[1][3] - brackets[1][2]) * rates[3];

else if(taxableIncome<=372950)

tax=brackets[1][0] * rates[0]+

(brackets[1][1] - brackets[1][0]) * rates[1] +

(brackets[1][2] - brackets[1][1]) * rates[2] +

(brackets[1][3] - brackets[1][2]) * rates[3] +

(brackets[1][4] - brackets[1][3]) * rates[4];

else

tax=brackets[1][0] * rates[0]+

(brackets[1][1] - brackets[1][0]) * rates[1] +

(brackets[1][2] - brackets[1][1]) * rates[2] +

(brackets[1][3] - brackets[1][2]) * rates[3] +

(brackets[1][4] - brackets[1][3]) * rates[4] +

(taxableIncome - brackets[1][4]) * rates[5];

}else if(status==2) {

if(taxableIncome<=8350)

tax=brackets[2][0] * rates[0];

else if(taxableIncome<=33950)

tax=brackets[2][0] * rates[0]+

(brackets[2][1] - brackets[2][0]) * rates[1];

else if(taxableIncome<=68525)

tax=brackets[2][0] * rates[0]+

(brackets[2][1] - brackets[2][0]) * rates[1] +

(brackets[2][2] - brackets[2][1]) * rates[2];

else if(taxableIncome<=104425)

tax=brackets[2][0] * rates[0]+

(brackets[2][1] - brackets[2][0]) * rates[1] +

(brackets[2][2] - brackets[2][1]) * rates[2] +

(brackets[2][3] - brackets[2][2]) * rates[3];

else if(taxableIncome<=186475)

tax=brackets[2][0] * rates[0]+

(brackets[2][1] - brackets[2][0]) * rates[1] +

(brackets[2][2] - brackets[2][1]) * rates[2] +

(brackets[2][3] - brackets[2][2]) * rates[3] +

(brackets[2][4] - brackets[2][3]) * rates[4] ;

else

tax=brackets[2][0] * rates[0]+

(brackets[2][1] - brackets[2][0]) * rates[1] +

(brackets[2][2] - brackets[2][1]) * rates[2] +

(brackets[2][3] - brackets[2][2]) * rates[3] +

(brackets[2][4] - brackets[2][3]) * rates[4] +

(taxableIncome - brackets[2][4]) * rates[5] ;

}else if(status==3) {

if(taxableIncome<=11950)

tax=brackets[3][0] * rates[0];

else if(taxableIncome<=45500)

tax=11950*0.1+(taxableIncome-11950)*0.15;

else if(taxableIncome<=117450)

tax=11950*0.1+(45500-11950)*0.15+(taxableIncome-45500)*0.25;

else if(taxableIncome<=190200)

tax=11950*0.1+(45500-11950)*0.15+(117450-45500)*0.25+(taxableIncome-117450)*0.28;

else if(taxableIncome<=372950)

tax=11950*0.1+(45500-11950)*0.15+(117450-45500)*0.25+(190200-117450)*0.28+(taxableIncome-190200)*0.33;

else

tax=brackets[3][0] * rates[0]+

(brackets[3][1] - brackets[3][0]) * rates[1] +

(brackets[3][2] - brackets[3][1]) * rates[2] +

(brackets[3][3] - brackets[3][2]) * rates[3] +

(brackets[3][4] - brackets[3][3]) * rates[4] +

(taxableIncome - brackets[3][4]) * rates[5];

}else{

System.out.println(“Error: invalid status”);

System.exit(1);

}

System.out.println("Tax is "+(int)(tax * 100) / 100.0);

}

}

8.13

=================================================================

import java.util.Scanner;

public class dibazhang {

public static void main(String[] args) {

System.out.print("Enter the number of rows and columns of the array: ");

Scanner input = new Scanner(System.in);

int r, c;

r = input.nextInt();

c = input.nextInt();

double[][] a = new double[r][c];

System.out.print(“Enter the array: \n”);

for (int i = 0; i < a.length; i++) {

for (int j = 0; j < a[i].length; j++) {

a[i][j] = input.nextDouble();

}

}

int[] p = new int[2];

p = locateLargest(a);

System.out.print(“The location of the largest element is at (” + p[0] + “,” + p[1] + “)”);

}

private static int[] locateLargest(double[][] a) {

int tmpArry[]=new int[2];

double tmp = 0;

for (int i = 0; i < a.length; i++) {

for (int j = 0; j < a[i].length; j++) {

if(tmp<a[i][j]){

tmp=a[i][j];

tmpArry[0]=i;

tmpArry[1]=j;

}

}

}

return tmpArry;

}

}

8.14

=================================================================

import java.util.Random;

import java.util.Scanner;

public class dibazhang {

public static void main(String[] args) {

System.out.print("Enter the size for the matrix: ");

Scanner input = new Scanner(System.in);

int row = input.nextInt();

Random random = new Random();

int[][] a = new int[row + 1][row + 1];

for (int i = 1; i <= row; i++) {

for (int j = 1; j <= row; j++) {

a[i][j] = random.nextInt(2);

System.out.print(a[i][j]);

}

System.out.println();

}

int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;

for (int i = 1; i <= row; i++) {

sum1 = 0;

sum2 = 0;

for (int j = 1; j <= row; j++) {

sum1 += a[i][j];

sum2 += a[j][i];

}

if (sum1 == 0) {

System.out.println("All 0s on row " + i);

}else if (sum1 == 4) {

System.out.println("All 1s on row " + i);

}

if (sum2 == 0) {

System.out.println("All 0s on column " + i );

} else if (sum2 == 4) {

System.out.println(“All 1s on column” + i);

}

}

for (int i = 1; i <= row; i++) {

sum3 += a[i][i];

}

if (sum3 == 0) {

System.out.println(“All 0s on major diagonal”);

}else if (sum3 == 4) {

System.out.println(“All 1s on major diagonal”);

} else {

System.out.println(“No same numbers on the major diagonal”);

}

for (int i = 1; i <= row; i++) {

sum4 += a[i][row + 1 - i];

}

if (sum4 == 0) {

System.out.println(“All 0s on sub-diagonal”);

} else if (sum4 == 4) {

System.out.println(“All 1s on sub-diagonal”);

} else {

System.out.println(“No same numbers on the sub-diagonal”);

}

input.close();

}

}

8.15

=================================================================

import java.util.Scanner;

public class dibazhang {

public static void main(String[] args) {

System.out.print("Enter five points: ");

Scanner input = new Scanner(System.in);

double[][] points = new double[5][2];

for(int i=0;i<5;i++)

for(int j=0;j<2;j++)

points[i][j]=input.nextDouble();

if(onTheSameLine(points[0][0], points[0][1], points[1][0], points[1][1], points[2][0], points[2][1])

&& onTheSameLine(points[0][0], points[0][1], points[1][0], points[1][1], points[3][0], points[3][1])

&& onTheSameLine(points[0][0], points[0][1], points[1][0], points[1][1], points[4][0], points[4][1]))

System.out.print(“The five points are on the same line”);

else

System.out.print(“The five points are not on the same line”);

}

public static boolean onTheSameLine(double x0,double y0,double x1,double y1,double x2,double y2){

return (x1-x0)(y2-y0)-(x2-x0)(y1-y0)==0;

}

}

8.16

=================================================================

import java.util.Scanner;

public class dibazhang {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter row and column: ");

int r = input.nextInt();

int c = input.nextInt();

int[][] m = new int[r][c];

System.out.print("Enter the values: ");

for (int i = 0; i < r; i++)

for (int j = 0; j < c; j++)

m[i][j] = input.nextInt();

sort(m);

}

public static void sort(int[][] m) {

int count = 0;

while (count < m.length) {

for (int i = 0; i < m.length - 1; i++) {

// 遍历m[i]数组中的值,判断m[i],m[i+1]是否交换位置

for (int j = 0; j < m[i].length; j++) {

if (m[i][j] > m[i + 1][j]) {

int temp[];

temp = m[i];

m[i] = m[i + 1];

m[i + 1] = temp;

j = 0;

break;

}

if (m[i][j] < m[i + 1][j]) {

break;

}

if (m[i][j] == m[i + 1][j]) {

continue;

}

}

}

count++;

}

// print

System.out.print("sorted: ");

for (int[] j : m) {

System.out.print(“(”);

for (int i = 0; i < j.length; i++) {

System.out.printf(" %d ", j[i]);

}

System.out.print(") ");

}

// 4 2 1 7 4 5 1 2 1 1 4 1}

}

8.17

=================================================================

import java.util.Scanner;

public class dibazhang {

public static void main(String[] args){

Scanner input = new Scanner(System.in);

int n = input.nextInt();

int limit = input.nextInt();

double[][] loans =new double[n][n];

double[] balances = new double[n];

for(int i=0;i<n;i++){

balances[i] = input.nextDouble();

int ass = input.nextInt();

for(int j=0;j<ass;j++){

int borrower = input.nextInt();

loans[i][borrower]=input.nextDouble();

}

}

System.out.print("Unsafe banks are ");

boolean[] printed = new boolean[n];

for(int i=0;i<n;i++)

printed[i]=false;

while(true){

boolean changed = false;

for(int i=0;i<n;i++){

double sum = balances[i];

for(int j=0;j<n;j++)

sum+=loans[i][j];

if(sum<limit){

if(!printed[i]) {

System.out.print(i + " ");

printed[i] = true;

changed=true;

}

for(int k=0;k<n;k++)

loans[k][i]=0;

}

}

if(!changed)

break;

}

}

}

8.18

=================================================================

import java.util.ArrayList;

import java.util.List;

import java.util.Random;

import java.util.Scanner;

public class dibazhang {

public static void main(String[] args) {

int[][] m = { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }, { 9, 10 } };

shuffle(m);

}

public static void shuffle(int m[][]) {

// 判断是否为空

if (m == null) {

return;

}

// 获取原数组信息 n*m 以及 length

int N = m.length;

int M = m[0].length;

int len = N * M;

// 生成一个和原来二维数组规格一样的数组

int[][] copy = new int[N][M];

// 生成随机数下标,存放到数组中

// 存放行坐标

List indexI = new ArrayList();

// 存放列坐标

List indexJ = new ArrayList();

Random random = new Random();

while (indexI.size() != N) {

int ran = random.nextInt(N);

if (!indexI.contains(ran)) {

indexI.add(ran);

}

}

while (indexJ.size() != M) {

int ran = random.nextInt(M);

if (!indexJ.contains(ran)) {

indexJ.add(ran);

}

}

// 使用原数组为新数组赋值

for (int i = 0; i < N; i++) {

for (int j = 0; j < M; j++) {

int p = (int) indexI.get(i);

int q = (int) indexJ.get(j);

copy[i][j] = m[p][q];

}

}

// print

m = copy;

for (int i = 0; i < N; i++) {

System.out.print(“(”);

for (int j = 0; j < M; j++) {

System.out.printf(" %d ", m[i][j]);

}

System.out.println(“)”);

}

}

}

8.19

=================================================================

import java.util.Scanner;

public class dibazhang {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner input = new Scanner(System.in);

int rows;

int columns;

System.out.print("Enter the number of rows: ");

rows = input.nextInt();

System.out.print("Enter the number of columns: ");

columns = input.nextInt();

int[][] jesus = new int[rows][columns];

System.out.println("Enter the matrix: ");

for(int i=0;i<rows;i++)

for(int j=0;j<columns;j++)

jesus[i][j] = input.nextInt();

System.out.println(isConsecutiveFour(jesus));

2021年Java中高级面试必备知识点总结

在这个部分总结了2019年到目前为止Java常见面试问题,取其面试核心编写成这份文档笔记,从中分析面试官的心理,摸清面试官的“套路”,可以说搞定90%以上的Java中高级面试没一点难度。

本节总结的内容涵盖了:消息队列、Redis缓存、分库分表、读写分离、设计高并发系统、分布式系统、高可用系统、SpringCloud微服务架构等一系列互联网主流高级技术的知识点。

目录:

(上述只是一个整体目录大纲,每个点里面都有如下所示的详细内容,从面试问题——分析面试官心理——剖析面试题——完美解答的一个过程)

部分内容:

对于每一个做技术的来说,学习是不能停止的,小编把2019年到目前为止Java的核心知识提炼出来了,无论你现在是处于什么阶段,如你所见,这份文档的内容无论是对于你找面试工作还是提升技术广度深度都是完美的。

不想被后浪淘汰的话,赶紧搞起来吧,高清完整版一共是888页,需要的话可以点赞+关注
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!
or(int j=0;j<columns;j++)

jesus[i][j] = input.nextInt();

System.out.println(isConsecutiveFour(jesus));

2021年Java中高级面试必备知识点总结

在这个部分总结了2019年到目前为止Java常见面试问题,取其面试核心编写成这份文档笔记,从中分析面试官的心理,摸清面试官的“套路”,可以说搞定90%以上的Java中高级面试没一点难度。

本节总结的内容涵盖了:消息队列、Redis缓存、分库分表、读写分离、设计高并发系统、分布式系统、高可用系统、SpringCloud微服务架构等一系列互联网主流高级技术的知识点。

目录:

[外链图片转存中…(img-2Q3rjdIY-1714693187753)]

(上述只是一个整体目录大纲,每个点里面都有如下所示的详细内容,从面试问题——分析面试官心理——剖析面试题——完美解答的一个过程)

[外链图片转存中…(img-JDHlplJq-1714693187754)]

部分内容:

[外链图片转存中…(img-j8ZqkwbD-1714693187754)]

[外链图片转存中…(img-CB9E1IVE-1714693187755)]

[外链图片转存中…(img-9blutavj-1714693187755)]

对于每一个做技术的来说,学习是不能停止的,小编把2019年到目前为止Java的核心知识提炼出来了,无论你现在是处于什么阶段,如你所见,这份文档的内容无论是对于你找面试工作还是提升技术广度深度都是完美的。

不想被后浪淘汰的话,赶紧搞起来吧,高清完整版一共是888页,需要的话可以点赞+关注
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!

  • 23
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值