【Java学习】变量、运算符、表达式、输入与输出

1. A+B
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(a + b);
    }
}
2. 差
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        System.out.printf("DIFERENCA = %d\n", a * b - c * d);
    }
}
3. 圆的面积
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        System.out.printf("A=%.4f\n", 3.14159 * r * r);
    }
}
4. 平均数1
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        System.out.printf("MEDIA = %.5f\n", (3.5 * a + 7.5 * b)/(3.5 + 7.5));
    }
}
5. 工资
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        System.out.printf("NUMBER = %d\n", a);
        System.out.printf("SALARY = U$ %.2f\n", b * c);
    }
}
6. 油耗
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        double b = sc.nextDouble();
        System.out.printf("%.3f km/l\n", a / b);
    }
}
7. 两点之间的距离
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        double d = sc.nextDouble();
        System.out.printf("%.4f\n", Math.sqrt((a - c) * (a - c) + (b - d) * (b - d)));
    }
}
8. 钞票
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.printf("%d\n", N);
        System.out.printf("%d nota(s) de R$ 100,00\n", N / 100);
        N = N % 100;
        System.out.printf("%d nota(s) de R$ 50,00\n", N / 50);
        N = N % 50;
        System.out.printf("%d nota(s) de R$ 20,00\n", N / 20);
        N = N % 20;
        System.out.printf("%d nota(s) de R$ 10,00\n", N / 10);
        N = N % 10;
        System.out.printf("%d nota(s) de R$ 5,00\n", N / 5);
        N = N % 5;
        System.out.printf("%d nota(s) de R$ 2,00\n", N / 2);
        N = N % 2;
        System.out.printf("%d nota(s) de R$ 1,00\n", N);
    }
}
9. 时间转换
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.printf("%d:%d:%d\n", N / 3600, (N % 3600) / 60, N % 3600 % 60);
    }
}
10. 简单乘积
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        System.out.printf("PROD = %d\n", (N * M));
    }
}
11. 简单计算
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        double c = sc.nextDouble();
        int a1 = sc.nextInt();
        int b1 = sc.nextInt();
        double c1 = sc.nextDouble();
        System.out.printf("VALOR A PAGAR: R$ %.2f\n", b * c + b1 * c1);
    }
}
12. 球的体积
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        System.out.printf("VOLUME = %.3f\n", 3.14159
*(4/3.0)*a*a*a);
    }
}
13. 面积
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        System.out.printf("TRIANGULO: %.3f\n", a*c/2);
        System.out.printf("CIRCULO: %.3f\n", 3.14159*c*c);
        System.out.printf("TRAPEZIO: %.3f\n", (a+b)*c/2);
        System.out.printf("QUADRADO: %.3f\n", b*b);
        System.out.printf("RETANGULO: %.3f\n", a*b);
    }
}
14. 平均数2
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        System.out.printf("MEDIA = %.1f\n", (a*2+b*3+c*5)/10);
    }
}
15. 工资和奖金
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        System.out.printf("TOTAL = R$ %.2f\n", b + 0.15 * c);
    }
}
16. 最大值
java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        a = (a + b + Math.abs(a - b))/2;
        a = (a + c + Math.abs(a - c))/2;
        System.out.printf("%d eh o maior\n", a);
    }
}
相关推荐
Fireworkitte3 小时前
Apache POI 详解 - Java 操作 Excel/Word/PPT
java·apache·excel
weixin-a153003083163 小时前
【playwright篇】教程(十七)[html元素知识]
java·前端·html
DCTANT4 小时前
【原创】国产化适配-全量迁移MySQL数据到OpenGauss数据库
java·数据库·spring boot·mysql·opengauss
sealaugh324 小时前
aws(学习笔记第四十八课) appsync-graphql-dynamodb
笔记·学习·aws
Touper.4 小时前
SpringBoot -- 自动配置原理
java·spring boot·后端
黄雪超4 小时前
JVM——函数式语法糖:如何使用Function、Stream来编写函数式程序?
java·开发语言·jvm
ThetaarSofVenice4 小时前
对象的finalization机制Test
java·开发语言·jvm
水木兰亭4 小时前
数据结构之——树及树的存储
数据结构·c++·学习·算法
思则变4 小时前
[Pytest] [Part 2]增加 log功能
开发语言·python·pytest
鱼摆摆拜拜4 小时前
第 3 章:神经网络如何学习
人工智能·神经网络·学习