我给社区中的每个人留下了一份训练编程逻辑的练习清单。
(我为每一个留下了我的解决方案,使用Java语言)
练习
1 - 创建一个算法,读取 A、B、C 的值,然后在屏幕上打印 A 和 B 之间的总和,并显示总和是否小于 C。
package org.example; import java.util.Scanner; public class Main { public static void main(String[] args) { System.out.println("Write a value of A:"); Scanner integerScanner = new Scanner(System.in); int A = Integer.parseInt(integerScanner.next()); System.out.println("Write a value of B:"); int B = Integer.parseInt(integerScanner.next()); System.out.println("Write a value of C:"); int C = Integer.parseInt(integerScanner.next()); int sum = A + B ; if (sum <= C){ System.out.println("The result of value A + B is: " + sum + ";\nThe sum of A + B is less or equal value C"); } else{ System.out.println("The result of value A + B is: " + sum + ";\nThe sum of A + B dont is less or equal value C"); } } }
2 - 创建一个算法来接收任何数字并在屏幕上打印,无论该数字是偶数还是奇数、正数还是负数。
package org.example; import java.util.Scanner; public class Main { public static void main(String[] args) { System.out.println("Write a number:"); Scanner integerScanner = new Scanner(System.in); int number = Integer.parseInt(integerScanner.next()); if (number >=0){ if (number % 2 == 0){ System.out.println("The number " + number + " is 'even' = par and positive"); } else System.out.println("The number " + number + " is 'odd' = impar and positive"); } else { if (number % 2 == 0){ System.out.println("The number " + number + " is 'even' = par and negative"); } else System.out.println("The number " + number + " is 'odd' = impar and negative"); } } }
3 - 制作一个算法,读取两个整数值A和B,如果A和B的值相等,则必须将这两个值相加,
否则您必须将 A 乘以 B。在任何计算结束时,您必须将结果分配给变量 C 和
在屏幕上打印您的值。
package org.example; import java.util.Scanner; public class Main { public static void main(String[] args) { System.out.println("Write your first value:"); Scanner integerScanner = new Scanner(System.in); int A = integerScanner.nextInt(); System.out.println("Write your second value:"); int B = integerScanner.nextInt(); int C; if (A == B){ C = A + B; System.out.println("The sum off A + B is: " + C); } else { C = (A * B); System.out.println("The multiple of A x B is: " + C); } } }
4 - 创建一个接收整数并在屏幕上打印其前任和后继的算法。
package org.example; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner integerScanner = new Scanner(System.in); System.out.println("Write your number: "); int number = integerScanner.nextInt(); int nextNumber = number + 1; int previousNumber = number - 1; System.out.println("The next number is: " + nextNumber); System.out.println("The previous number is: " + previousNumber); } }
5 - 创建一个算法,读取最低工资的值和用户工资的值,计算这个最低工资是多少
用户获胜并在屏幕上打印结果。 (最低工资基数为 1,293.20 雷亚尔)。
package org.example; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner doubleScanner = new Scanner(System.in); System.out.println("Write your salario: "); double salarioMin = 1293.20; double salario = doubleScanner.nextDouble(); double total = salario / salarioMin; System.out.printf("the salario is: %.2fx o salario min" , total); } }
6 - 创建一个算法,读取任何值并将其以 5% 的调整打印在屏幕上。
package org.example; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Write a value: "); double a = scanner.nextDouble(); double total = a *.05; double result = a + total; System.out.printf("the value with 5%% increase is: %.2f" , result); } }
7 - 创建一个算法,读取两个布尔(逻辑)值并确定它们是 TRUE 还是 FALSE。
package org.example; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Write a boolean value: "); boolean value1 = scanner.nextBoolean(); System.out.print("Write other boolean value: "); boolean value2 = scanner.nextBoolean(); if (value1 && value2){ System.out.println("values are true"); } else if (!value1 && !value2){ System.out.println("values are false"); } else { System.out.println("value are different"); } } }
8 - 制作一个算法,读取三个不同的整数值并按降序在屏幕上打印这些值。
package org.example; import java.util.Scanner; import java.util.Arrays; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Write your first value"); int value1 = scanner.nextInt(); System.out.println("Write your second value"); int value2 = scanner.nextInt(); System.out.println("Write your third value"); int value3 = scanner.nextInt(); int[] values = {value1, value2, value3}; Arrays.sort(values); System.out.println("Values in descending order:"); for (int i = values.length - 1; i >= 0; i--) { System.out.print(values[i] + " "); } } }
9 - 创建一个算法来计算一个人的 BMI(身体质量指数),读取他们的体重和身高并在屏幕上打印他们的状况
根据下表:
BMI公式=体重/(身高)²
BMI状况表
低于18.5 |体重不足
18.6 至 24.9 之间 |理想体重(恭喜)
25.0 至 29.9 之间 |有点超重
30.0 至 34.9 之间 |肥胖I级
35.0 至 39.9 之间 |肥胖II级(重度)
大于或等于 40 | III级肥胖(病态)
Em breve
10 - 创建一个算法,读取学生获得的三个成绩,并在屏幕上打印成绩的平均值。
package org.example; import java.util.Scanner; public class Main { public static void main(String[] args) { System.out.println("Write your first grade"); Scanner integerScanner = new Scanner(System.in); int grade = Integer.parseInt(integerScanner.next()); System.out.println("Write your second grade"); int grade2 = Integer.parseInt(integerScanner.next()); System.out.println("Write your third grade"); int grade3 = Integer.parseInt(integerScanner.next()); int sum = grade3 + grade + grade2; float result = (float)sum /3; System.out.printf("Your average grade is: %.1f" , result); } }
11 - 创建一个算法,读取学生获得的四个成绩,计算所获得成绩的平均值,在屏幕上打印学生的姓名,然后
学生是否通过或未通过。要使学生被视为获得批准,其最终平均分必须大于或等于 7。
Em breve
12 - 创建一个算法来读取产品的价值并根据选择的付款方式确定必须支付的金额
由买家在屏幕上打印要支付的产品的最终价值。使用付款条件表中的代码进行适当的计算。
付款条款代码表
1 - 现金或 Pix,享受 15% 折扣
2 - 信用卡现金,享受 10% 折扣
3 - 卡上分两期付款,产品正常价格,无利息
4 - 卡内分三期或以上分期付款,产品正常价格加 10% 利息
Em breve
13 - 创建一个算法,读取一个人的姓名和年龄,并在屏幕上打印这个人的名字以及他们是年长还是年轻。
Em breve
14 - 制作一个算法,接收值 A 和 B,并将 A 的值交换为 B,将 B 的值交换为 A,并将这些值打印在屏幕上。
Em breve
15 - 创建一个算法来读取一个人的出生年份,并在屏幕上打印该人已经活了多少年、月和天。带到
考虑一年有365天,月份有30天。
(例如:生命的 5 年零 2 个月又 15 天)
Em breve
16 - 制作一个算法,读取代表三角形三边的三个值并检查它们是否有效,确定三角形是否
等边、等腰或不等边角。
Em breve
17 - 制定一个算法,读取华氏温度并计算相应的摄氏度温度。在屏幕上打印两个温度。
Em breve
公式:C = (5 * (F-32) / 9)
18 - Francisco 身高 1.50m,每年增长 2 厘米,而 Sara 身高 1.10m,每年增长 3 厘米。创建一个算法,计算并在屏幕上打印弗朗西斯科需要多少年才能比莎拉更大。
Em breve
19 - 创建一个算法,在屏幕上打印 1 到 10 的乘法表。
Em breve
20 - 创建一个接收整数值并在屏幕上打印其乘法表的算法。
Em breve
21 - Faça um algoritmo que mostre um valor aleatório entre 0 e 100.
Em breve
22 - Faça um algoritmo que leia dois valores inteiros A e B, imprima na tela o quociente e o resto da divisão inteira entre eles.
Em breve
21 - Faça um algoritmo que efetue o cálculo do salário líquido de um professor. As informações fornecidas serão: valor da hora aula, número de aulas lecionadas no mês e percentual de desconto do INSS. Imprima na tela o salário líquido final.
Em breve
22 - Faça um algoritmo que calcule a quantidade de litros de combustível gastos em uma viagem, sabendo que o carro faz 12km com um litro. Deve-se fornecer ao usuário o tempo que será gasto na viagem a sua velocidade média, distância percorrida e a quantidade de litros utilizados para fazer a viagem.
Fórmula: distância = tempo x velocidade.
litros usados = distância / 12.
Em breve
Créditos:
Todos os exercícios da lista acima foram obtidos da DIO.
Link: https://www.dio.me/articles/lista-de-exercicios-para-treinar-logica-de-programacao
以上是训练编程逻辑的练习列表。的详细内容。更多信息请关注PHP中文网其他相关文章!