
我给社区中的每个人留下了一份训练编程逻辑的练习清单。
(我为每一个留下了我的解决方案,使用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.50 m,每年增长 2 厘米,而 sara 身高 1.10 m,每年增长 3 厘米。制作一个算法,计算并在屏幕上打印弗朗西斯科需要多少年才能比萨拉大。
em breve
19 - 创建一个算法,在屏幕上打印 1 到 10 的乘法表。
em breve
20 - 创建一个接收整数值并在屏幕上打印其乘法表的算法。
em breve
21 - 制作一个显示 0 到 100 之间的随机值的算法。
em breve
22 - 制作一个算法,读取两个整数值 a 和 b,在屏幕上打印它们之间的商和整数除法的余数。
em breve
21 - 创建一个计算教师净工资的算法。提供的信息包括:每小时的课程费用、当月教授的课程数量以及 inss 折扣百分比。在屏幕上打印最终净工资。
em breve
22 - 创建一个算法,计算一次旅行所消耗的燃油升数,已知汽车使用 1 升行驶 12 公里。用户必须提供行程所需的时间、平均速度、行驶距离以及行程所用的升数。
公式:距离=时间x速度。
使用的升数 = 距离 / 12.
em breve
学分:
上面列表中的所有练习均来自 dio。
链接:https://www.dio.me/articles/lista-de-exercicios-para-treinar-logica-de-programacao
以上就是训练编程逻辑的练习列表的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号