首页 > 其他分享 >Convert类型转换

Convert类型转换

时间:2024-08-10 15:16:16浏览次数:8  
标签:类型转换 intAllSecond Convert Console int 60 WriteLine

 

        static void Main(string[] args)
        {
            //Convert转换:不同数据类型之间的转换;
            //大前提: 面儿上一定要过得去

            Console.WriteLine("请输入你的姓名:");
            string strName = Console.ReadLine();
            Console.WriteLine("请输入你的数学成绩:");
            double douMath = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("请输入你的语文成绩:");
            double douChinese = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("请输入你的英语成绩:");
            double douEnglish = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("{0},你的总分是{1}, 你的平均分是{2:0.00};", strName, douMath + douChinese + douEnglish, (douMath + douChinese + douEnglish) / 3);
            
            if (douMath>=60 && douChinese>=60 && douEnglish>=60)
            {
                Console.WriteLine("恭喜你,成绩合格!");
            }
            else
            {
                Console.WriteLine("很抱歉, 你的部分成绩不合格!");
            }
            Console.ReadKey();
        }

 

        static void Main(string[] args)
        {
            Console.WriteLine("46天是{0}周零{1}天;", 46 / 7, 46 % 7);
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            const int intAllSecond= 107653;
            int intDay = intAllSecond / (24 * 60 * 60);
            int intHour = (intAllSecond % (24 * 60 * 60)) / (60 * 60);
            int intMinute= ((intAllSecond % (24 * 60 * 60)) % (60 * 60))/60;
            int intSecond= intAllSecond  % 60;
            Console.WriteLine("{0}天,{1}时,{2}分,{3}秒", intDay, intHour, intMinute, intSecond);
            Console.ReadKey();
        }

 

标签:类型转换,intAllSecond,Convert,Console,int,60,WriteLine
From: https://www.cnblogs.com/csflyw/p/18352313

相关文章

  • C++ 类型转换
    目录0.前言1.C语言类型转换1.1隐式类型转换1.2显式类型转换2.C++强制类型转换2.1static_cast2.2reinterpret_cast2.3const_cast2.4dynamic_cast3.为什么C++需要4种强制类型转换3.1类型转换的多样性需求3.2提高类型转换的安全性3.3提供更明确的语义3.4支持高......
  • JsonConvert中处理Null值问题
    1.定义一个类 NullToEmptyStringConverter 继承 JsonConverterusingNewtonsoft.Json;usingNewtonsoft.Json.Linq;usingSystem;publicclassNullToEmptyStringConverter:JsonConverter{publicoverrideboolCanConvert(TypeobjectType){returntrue;......
  • 基本数据类型转换
    五、基本数据类型转换自动类型转换:容量小的类型自动转换为容量大的数据类型。数据类型按容量大小排序为:有多种类型的数据混合运算时,系统首先自动将所有数据转换成容量最大的那种数据类型,然后再进行计算。byte,short,char之间不会相互转换,他们三者在计算时首先转换为int类型。......
  • 引入JaCoCo导致的类型转换问题分析
    一、问题描述JaCoCo是一款被广泛应用于公司内部的开源覆盖率工具,将其引用至测试环境后,机器启动正常,但在操作下单时出现异常,阻塞下单流程。去除JaCoCo配置、重新编译和部署后下单功能恢复正常。堆栈信息显示,问题源于系统对请求字段进行加密时出现异常,因为无法完成类型转换抛出异......
  • ABAP数据类型转换和不同数据类型比较
    DATA:lv_strTYPEstring,lv_str2TYPEstring,lv_charTYPEchar10,lv_iTYPEiVALUE1,lv_fTYPEpDECIMALS1VALUE'1.1'.lv_str='1.11'.lv_char='1.11'."TRUEIFlv_str=1.WRITE:1......
  • LeetCode 1017. Convert to Base -2
    原题链接在这里:https://leetcode.com/problems/convert-to-base-2/description/题目:Givenaninteger n,return abinarystringrepresentingitsrepresentationinbase -2.Note thatthereturnedstringshouldnothaveleadingzerosunlessthestringis "0".......
  • 类型转换
    1.类型转换优先级如图所示2.转换方法强制转换自动转换3.转换问题1.内存溢出:在大容量转换为小容量时,如果容量过大而超过了小容量的类所能承受的范围,则会出错。如:2.精确问题:在小数转整数时,会出现误差如:3.相乘问题:未转换,已相乘。如:解决方法:......
  • 对于泛型和类型转换的优先级
    你们猜猜谁先打印,不看答案,能猜出来吗,写在评论区下面有3道题目,分别写出答案在评论区1、classTest{publicstaticvoidMain(){Foo("Hello");}publicstaticvoidFoo(objectx){Console.WriteLine("object");......
  • Qt C++ 调用 Python 之 PyObject* 数据类型转换
    整数:PyLong_FromLong和PyLong_AsLong类型检查函数:PyLong_Check()intcppInt=42;//C++整数转换为Python整数对象PyObject*pyInt=PyLong_FromLong(cppInt);//Python整数对象转换为C++整数longcppIntFromPy=PyLong_AsLong(pyInt);Py_DECREF(pyInt)......
  • 类型转换运算符
    1.作用类通过自定义的类型转换运算符,可以将一个类型转换成另一个类型。例如将自定义的Student类转换成std::string类。虽然在格式上和运算符重载类似,但运算符重载是一个成员函数,而类型转换运算符不是,因为没有返回值。2.格式operatortype()[const];type:表示转化后的数据......