
初学java程序错误
编译运行都通过了,但是结果却始终不对!我想做一个统计双色球06年号码的小程序,输入文件是100多条7位双色球号码,每条的前6位号码做统计,最后一个号码蓝球号码另做统计,最...
编译运行都通过了,但是结果却始终不对!
我想做一个统计双色球06年号码的小程序,输入文件是100多条7位双色球号码,每条的前6位号码做统计,最后一个号码蓝球号码另做统计,最后屏幕打印a:前6位,1——32号数字出现次数;b:后一位,1——32号数字出现的次数!
java程序:
import java.util.*;
import java.io.*;
import java.awt.*;
import java.lang.*;
public class aasd
{
private int[] sum;
private int[] lan;
private int i;
public aasd()
{
sum=new int[33];
lan=new int[33];
for(i=0;i<=32;i++)
{ sum[i]=0;
lan[i]=1;
}
theMain();
pAll();
}
public void theMain()
{
try
{
RandomAccessFile rf=new RandomAccessFile("c:\\myjava\2006.txt","r");
int j1,j2,j3;
j2=(int)rf.length();
rf.seek(0);
for(j1=1;j1<=j2;j1++)
{
for(j3=1;j3<=6;j3++)
{ sum[rf.readInt()]++; }
lan[rf.readInt()]++;
}
}catch(IOException e)
{
System.out.println("File access error: "+e);
}
}
public void pAll()
{
for(int i3=1;i3<=32;i3++)
{
System.out.print(i3+" ");
System.out.print(sum[i3]+" ");
System.out.println(lan[i3]+" ");
}
}
public static void main(String args[])
{
Asd a=new Asd();
}
}
RandomAccessFile rf=new RandomAccessFile("c:\\myjava\2006.txt","r");
Asd a=new Asd();
这俩个我已发现
主要是如何将字符型文件中的字符读出来成整形数字! 展开
我想做一个统计双色球06年号码的小程序,输入文件是100多条7位双色球号码,每条的前6位号码做统计,最后一个号码蓝球号码另做统计,最后屏幕打印a:前6位,1——32号数字出现次数;b:后一位,1——32号数字出现的次数!
java程序:
import java.util.*;
import java.io.*;
import java.awt.*;
import java.lang.*;
public class aasd
{
private int[] sum;
private int[] lan;
private int i;
public aasd()
{
sum=new int[33];
lan=new int[33];
for(i=0;i<=32;i++)
{ sum[i]=0;
lan[i]=1;
}
theMain();
pAll();
}
public void theMain()
{
try
{
RandomAccessFile rf=new RandomAccessFile("c:\\myjava\2006.txt","r");
int j1,j2,j3;
j2=(int)rf.length();
rf.seek(0);
for(j1=1;j1<=j2;j1++)
{
for(j3=1;j3<=6;j3++)
{ sum[rf.readInt()]++; }
lan[rf.readInt()]++;
}
}catch(IOException e)
{
System.out.println("File access error: "+e);
}
}
public void pAll()
{
for(int i3=1;i3<=32;i3++)
{
System.out.print(i3+" ");
System.out.print(sum[i3]+" ");
System.out.println(lan[i3]+" ");
}
}
public static void main(String args[])
{
Asd a=new Asd();
}
}
RandomAccessFile rf=new RandomAccessFile("c:\\myjava\2006.txt","r");
Asd a=new Asd();
这俩个我已发现
主要是如何将字符型文件中的字符读出来成整形数字! 展开
3个回答
展开全部
import java.io.IOException;
import java.io.RandomAccessFile;
public class Asd {
public static void main(String args[]) {
int[] sum = new int[32];
int[] lan = new int[32];
for (int i = 0; i < 32; i++) {
sum[i] = 0;
lan[i] = 0;
}
try {
RandomAccessFile rf = new RandomAccessFile("f:\\t.txt", "r");
String s;
while ((s = rf.readLine()) != null) {
String[] ss = s.split(" ");
for (int i = 0; i < ss.length; i++) {
if (i == ss.length - 1) {
lan[Integer.parseInt(ss[i]) - 1]++;
} else {
sum[Integer.parseInt(ss[i]) - 1]++;
}
}
}
rf.close();
for (int i3 = 0; i3 < 32; i3++) {
if (i3 < 9) {
System.out.print("0" + (i3 + 1) + " ");
} else {
System.out.print(i3 + 1 + " ");
}
System.out.print(sum[i3] + " ");
System.out.println(lan[i3] + " ");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
}
}
}
import java.io.RandomAccessFile;
public class Asd {
public static void main(String args[]) {
int[] sum = new int[32];
int[] lan = new int[32];
for (int i = 0; i < 32; i++) {
sum[i] = 0;
lan[i] = 0;
}
try {
RandomAccessFile rf = new RandomAccessFile("f:\\t.txt", "r");
String s;
while ((s = rf.readLine()) != null) {
String[] ss = s.split(" ");
for (int i = 0; i < ss.length; i++) {
if (i == ss.length - 1) {
lan[Integer.parseInt(ss[i]) - 1]++;
} else {
sum[Integer.parseInt(ss[i]) - 1]++;
}
}
}
rf.close();
for (int i3 = 0; i3 < 32; i3++) {
if (i3 < 9) {
System.out.print("0" + (i3 + 1) + " ");
} else {
System.out.print(i3 + 1 + " ");
}
System.out.print(sum[i3] + " ");
System.out.println(lan[i3] + " ");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
}
}
}
展开全部
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Asd {
private static int[] sum = new int[33];
private static int[] lan = new int[33];
public Asd() {
for (int i = 0; i < 33; i++) {
sum[i] = 0;
lan[i] = 0;
}
theMain();
pAll();
}
public static void theMain() {
try {
BufferedReader rf = new BufferedReader(new FileReader("f:\\t.txt"));
// RandomAccessFile rf = new RandomAccessFile("f:\\t.txt", "r");
String s;
while ((s = rf.readLine()) != null) {
String[] ss = s.split(" ");
//ss存放7个数据 前六个的判断要放到sum中 后一个要放到lan中
// System.out.println(ss.length);
for (int i = 0; i < ss.length; i++) {
int now = Integer.parseInt(ss[i]);
if (i == 6) {
int m=now - 1;
lan[m]++;
} else {
int n=now - 1;
sum[n]++;
}
}
}
} catch (IOException e) {
System.out.println("File access error: " + e);
}
}
public static void pAll() {
for (int i3 = 0; i3 < 32; i3++) {
System.out.print(i3 + 1 + " ");
System.out.print(sum[i3] + " ");
System.out.println(lan[i3] + " ");
}
}
public static void main(String args[]) {
Asd a = new Asd();
//theMain();
//pAll();a
}
}
import java.io.FileReader;
import java.io.IOException;
public class Asd {
private static int[] sum = new int[33];
private static int[] lan = new int[33];
public Asd() {
for (int i = 0; i < 33; i++) {
sum[i] = 0;
lan[i] = 0;
}
theMain();
pAll();
}
public static void theMain() {
try {
BufferedReader rf = new BufferedReader(new FileReader("f:\\t.txt"));
// RandomAccessFile rf = new RandomAccessFile("f:\\t.txt", "r");
String s;
while ((s = rf.readLine()) != null) {
String[] ss = s.split(" ");
//ss存放7个数据 前六个的判断要放到sum中 后一个要放到lan中
// System.out.println(ss.length);
for (int i = 0; i < ss.length; i++) {
int now = Integer.parseInt(ss[i]);
if (i == 6) {
int m=now - 1;
lan[m]++;
} else {
int n=now - 1;
sum[n]++;
}
}
}
} catch (IOException e) {
System.out.println("File access error: " + e);
}
}
public static void pAll() {
for (int i3 = 0; i3 < 32; i3++) {
System.out.print(i3 + 1 + " ");
System.out.print(sum[i3] + " ");
System.out.println(lan[i3] + " ");
}
}
public static void main(String args[]) {
Asd a = new Asd();
//theMain();
//pAll();a
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看看计算公式或类定义
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询