
我给社区里的每个人留下了一份训练编程逻辑的练习清单。 (我给每个人留下了我的解决方案,用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
<p>2 - 创建算法来接收任何数字并在屏幕上打印,无论数字是偶数还是奇数,正数还是负数。<br></p>
<pre class="brush:php;toolbar:false">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 之间 |肥胖i级(重度)
大于或等于40 |肥胖iiii级(病态)
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
以上是训练编程逻辑练习列表的详细内容。请关注图灵教育的其他相关文章!