首页 > 编程语言 >JAVA-Integer_int和string的相互转换

JAVA-Integer_int和string的相互转换

时间:2022-11-01 21:57:35浏览次数:38  
标签:string int System String println Integer out

package com.itheima;

public class intger_02 {
    public static void main(String[] args) {

        //int和string的相互转换
        int number=100;
        //方式一
        String s1=number+"";
        System.out.println(s1);
        //方式二
        String s2=String.valueOf(number);
        System.out.println(s2);
        System.out.println("-------------");

        //string....转换..int类型
        String s="100";
        //方式1 String-----Integer
        Integer i = Integer.valueOf(s);
        int x = i.intValue();
        System.out.println(x);
        //方式2
        int y = Integer.parseInt(s);
        System.out.println(y);



    }
}

执行结果


100
100
-------------
100

Process finished with exit code 0

标签:string,int,System,String,println,Integer,out
From: https://www.cnblogs.com/cy-xt/p/16849289.html

相关文章

  • JAVA-Integer_构造方法
    packagecom.itheima;publicclassintger_01{publicstaticvoidmain(String[]args){Integeri1=newInteger(100);//根据int做创建Integer对象(过时......
  • L - Intersection and Union Gym - 103993L (线段树)
    题意思路思路很巧妙,首先是枚举每个值的贡献,然后找到了规律,下次做题的时候线分析每个题有啥好规律,然后根据规律做题。再就是线段树的这个思路,感觉很巧妙,通过设置每一段的......
  • reinterpret_cast
       ......
  • human interface device
    hid设备:     ......
  • void USB_Init(uint8_t corenum, uint8_t mode);
    /*FunctionPrototypes:*/      /**MainfunctiontoinitializeandstarttheUSBinterface.Onceactive,theUSBinterfacewill      * allo......
  • int[] 的初始化
    一:int[]arr1=newint[1];//必须初始化数量,还有不初始化数字的arr1[0]=1;System.out.println("array1:"+Arrays.toString(arr1));二:int[]arr2={1,......
  • vue项目.editorconfig,.eslintgnore,.eslintrc配置编写规则文件
    1:介绍  ESLint是一个QA工具,用来避免低级错误和统一代码的风格,ESLint的主要用途:审查代码是否符合编码规范和统一的代码风格;审查代码是否存在语法错误;ESLint中文网地址......
  • 更改Android Studio默认ConstraintLayout布局
    看到网上很多人说改安装路径下的simple.xml.ftl里面的内容即可,可自己4.2.1版本并不存在AndroidStudio\plugins\android\lib\templates\activities\common\root\res\layou......
  • C++中string跨DLL失败解决途径
    1、问题描述:在一个MFC应用程序exe中,调用另一个DLL中的函数,函数中的一个形参是string类型的,每次调用都会出现乱码的情况,并且会崩溃。调用前:调用后: 2、原因分析: ......
  • C:02---scanf、printf
    一、printf​控制符①精度控制:输入小数点后m位(%.mf)。右对齐5位,保留小数点后m位(%d.mf)%f、%lf默认输出6位小数②宽度:%md(打印m为,右对齐,多出m位照常打印)。%-md(打印m位,左对齐,多......