【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);
    }
}
相关推荐
西阳未落2 小时前
C++基础(21)——内存管理
开发语言·c++·面试
我的xiaodoujiao2 小时前
Windows系统Web UI自动化测试学习系列2--环境搭建--Python-PyCharm-Selenium
开发语言·python·测试工具
callJJ2 小时前
从 0 开始理解 Spring 的核心思想 —— IoC 和 DI(2)
java·开发语言·后端·spring·ioc·di
wangjialelele2 小时前
Linux中的线程
java·linux·jvm·c++
谷咕咕2 小时前
windows下python3,LLaMA-Factory部署以及微调大模型,ollama运行对话,开放api,java,springboot项目调用
java·windows·语言模型·llama
没有bug.的程序员3 小时前
MVCC(多版本并发控制):InnoDB 高并发的核心技术
java·大数据·数据库·mysql·mvcc
在下村刘湘3 小时前
maven pom文件中<dependencyManagement><dependencies><dependency> 三者的区别
java·maven
hsjkdhs4 小时前
万字详解C++之构造函数析构函数
开发语言·c++
不务专业的程序员--阿飞4 小时前
JVM无法分配内存
java·jvm·spring boot
李昊哲小课4 小时前
Maven 完整教程
java·maven