【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);
    }
}
相关推荐
Gerardisite15 小时前
如何在微信个人号开发中有效管理API接口?
java·开发语言·python·微信·php
Want59515 小时前
C/C++跳动的爱心①
c语言·开发语言·c++
lingggggaaaa15 小时前
免杀对抗——C2远控篇&C&C++&DLL注入&过内存核晶&镂空新增&白加黑链&签名程序劫持
c语言·c++·学习·安全·网络安全·免杀对抗
coderxiaohan15 小时前
【C++】多态
开发语言·c++
gfdhy15 小时前
【c++】哈希算法深度解析:实现、核心作用与工业级应用
c语言·开发语言·c++·算法·密码学·哈希算法·哈希
闲人编程16 小时前
Python的导入系统:模块查找、加载和缓存机制
java·python·缓存·加载器·codecapsule·查找器
陈天伟教授16 小时前
基于学习的人工智能(5)机器学习基本框架
人工智能·学习·机器学习
我先去打把游戏先16 小时前
ESP32学习笔记(基于IDF):基于OneNet的ESP32的OTA功能
笔记·物联网·学习·云计算·iphone·aws
初願致夕霞16 小时前
学习笔记——基础hash思想及其简单C++实现
笔记·学习·哈希算法
Eiceblue16 小时前
通过 C# 将 HTML 转换为 RTF 富文本格式
开发语言·c#·html