java输入输出

Java中

byte 表示的是-128~127

short两个字节 32767

int 四个字节 -2147483648~2147483647 大概是21亿

long 八个字节 大概是10的18次方左右

double有效数字大概是15-16位

float有效数字大概是6-7位

输入两种方式
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        //String str1=sc.next();//next判定字符串时,遇到空白字符串结束
        //System.out.println(str1);
        String str2=sc.nextLine();//读入一行字符串,不管有多少空格
        System.out.println(str2);
        //int x=sc.nextInt();
        //System.out.println(x);
        //float f=sc.nextFloat();
        //System.out.println(f);
        //double d=sc.nextDouble();
        //System.out.println(d);
    }
}
import java.io.BufferedReader;//输入的规模大于10的5次方
import java.io.InputStreamReader;

public class Main{
    public static void main(String[] args)throws Exception{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String str=br.readLine();//读入一行,只能读入字符串
        System.out.println(str);
        //如果想读入整型数据,要手动转换
        /*int a=Integer.parseInt(br.readLine());//分行读入
        int b=Integer.parseInt(br.readLine());
        System.out.println(a+" "+b);*/
        
        /*String[] strs=br.readLine().split(" ");//读在一行里面
        int c=Integer.parseInt(strs[0]);
        int d=Integer.parseInt(strs[1]);
        System.out.println(c+" "+d);*/
    }
}
 输出两种方式
public class Main{
    public static void main(String[] args){
        System.out.println("hello");
        System.out.println(123);
        System.out.printf("%04d %.2f\n",4,3.33d);
    }
}
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;

public class Main{
    public static void main(String[] args) throws Exception{
        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
        bw.write("helloworld");
        bw.flush();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值