zoukankan      html  css  js  c++  java
  • 第一次上机作业

    package com.xuexiao;
    
    public class shangji {
        public static void main(String[] args) {
            //1、已知a,b均是整型变量,写出将a,b两个变量中 的值互换的程序。(知识点:变量和运算符综合 应用)
            int a = 1,b = 2;
            int c;
            c = a;
            a = b;
            b = c;
            System.out.println("a="+a+"
    "+"b="+b);
            
            
        }
        
    }

    package com.xuexiao;
    import java.util.Scanner;
    public class shangji {
        public static void main(String[] args) {
            
            //2、给定一个0~1000的整数,求各位数的和,例 如345的结果是3+4+5=12注:分解数字既可以先 除后模也可以先模后除(知识点:变量和运算符 综合应用) 
            Scanner sc = new Scanner(System.in);
            int s = sc.nextInt();
            int a = (s % 10) + (s / 10 % 10) + (s / 100 % 10)+(s / 1000 %10);
            System.out.println(s+"的各位数的和为:"+a);
        }
        
    }

    package com.xuexiao;
    import java.util.Scanner;
    public class shangji {
        public static void main(String[] args) {
            //3、华氏温度和摄氏温度互相转换,从华氏度变成 摄氏度你只要减去32,乘以5再除以9就行了,将 摄氏度转成华氏度,直接乘以9,除以5,再加上 32即行。
            System.out.println("如果想输入华氏温度请按1,如果想输入摄氏温度请按2");
            Scanner sc = new Scanner(System.in);
            int i= sc.nextInt();
            switch(i) {
                case 1:
                    System.out.println("请输入华氏度温度:");
                    int s = sc.nextInt();
                    int b = (s-32)*5/9;
                    System.out.println("华氏度"+s+"转为摄氏度:"+b);
                    break;
                case 2:
                    System.out.println("请输入摄氏度温度:");
                    int c = sc.nextInt();
                    int d = (c*9/5)+32;
                    System.out.println("摄氏度"+c+"转为华氏度:"+d);
                    break;
                default:
                    System.out.println("您的选择有误");
        }
        
    }}

    package com.xuexiao;
    import java.util.Scanner;
    public class shangji {
        public static void main(String[] args) {
            //4、给定一个任意的大写字母A~Z,转换为小写字 母。 (知识点:变量和运算符) 
            char a = 'A';
            System.out.println("转换之后为"+(char)(a+32));
    }}

  • 相关阅读:
    CF979D Kuro and GCD and XOR and SUM(01Trie)
    2020中国计量大学校赛题解
    CF16E Fish (状压dp)
    2017ccpc杭州站题解
    HDU6274 Master of Sequence(二分+预处理)
    CF899F Letters Removing(树状数组+二分)
    牛客 tokitsukaze and Soldier(优先队列+排序)
    HDU6268 Master of Subgraph(点分治)
    CF862E Mahmoud and Ehab and the function(二分)
    CF1108F MST Unification(生成树+思维)
  • 原文地址:https://www.cnblogs.com/tianzhiyuan/p/12523096.html
Copyright © 2011-2022 走看看