java文件读取整数(java读取整行)
华为云服务器特价优惠火热进行中! 2核2G2兆仅需 38 元;4核4G3兆仅需 79 元。购买时间越长越优惠!更多配置及优惠价格请咨询客服。
合作流程: |
今天给各位分享java文件读取整数的知识,其中也会对java读取整行进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
微信号:cloud7591如需了解更多,欢迎添加客服微信咨询。
复制微信号
本文目录一览:
Java怎么读取txt文件中的整数,并转化为数组
File file = new File("txt路径");
BufferedReader br = new BufferedReader(new FileReader(file));
ListInteger list = new ArrayListInteger();
String tmp;
while((tmp = br.readLine()) != null){
list.add(Integer.parseInt(tmp));
}
br.close();
java中从键盘读取整数
import java.util.Scanner;
/**
* 程序中原先存在的bug给你改了改,也可能还有没考虑进去的情况 你自己看看
* 你问的那个问题楼上的已经回答了,我只是给你改了下程序,可能跟你问的不对题^^
*
*/
public class StudentScore {
/**
* 程序要把整数小于-1和大于100情况考虑进去!
* 但非int型(double、 字符等)的情况也还是要考虑进去的,所以要加异常控制会好点
* @param args
*/
public static void main(String[] args) {
int s = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
Scanner keyboard = new Scanner(System.in);
int a;
try {
a = keyboard.nextInt();
//只有大于等于-1的情况才有意义
if(a=-1){
while (a != -1) {
switch (a / 10) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
b++;
s += a;
break;
case 6:
c++;
s += a;
break;
case 7:
d++;
s += a;
break;
case 8:
e++;
s += a;
break;
case 9:
case 10:
f++;
s += a;
break;
//如果分数超过100呢!
default: System.out.println(a+"超出分数范围");break;
}
a = keyboard.nextInt();
}
}
}
catch (Exception ex) { //非int型的异常捕获
// TODO: handle exception
}
System.out.println("优秀人数是:" + f);
System.out.println("良好人数是:" + e);
System.out.println("中等人数是:" + d);
System.out.println("及格人数是:" + c);
System.out.println("不及格人数是:" + b);
int average;
if(b + c + d + e + f0){
average = s / (b + c + d + e + f);
System.out.println("平均分是:" + average);
}
}
}
如何在java中读入整数
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入一个整数");
int x = scan.nextInt();
System.out.println("输入的证书是:"+x);
}

java怎样从键盘读取整型数据
public static void main(String[] args) throws ParseException {
Scanner in = new Scanner(System.in);
System.out.print("请输入整型数据:");
int i = in.nextInt();
System.out.print("你输入的数据是:"+i);
}
java文件读取整数的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java读取整行、java文件读取整数的信息别忘了在本站进行查找喔。
