错误:编写java类文件时出错

问题描述 投票:0回答:1

check this image for a screenshot of my cmd我正在尝试编译我的java代码并在命令提示符中收到此错误,我知道我遗漏了一些非常基本的东西。谢谢,

我在这里添加了整个代码,我的命令行截图也被添加了。我之前能够编译代码,现在它突然停止工作了。

C:\Users\Jaysurya\Desktop\cnlab\crc>javac crc.java
 crc.java:2: error: error while writing crc: 
 C:\Users\Jaysurya\Desktop\cnlab\crc\crc.class
 class crc
 ^
 1 error
 C:\Users\Jaysurya\Desktop\cnlab\crc

>

我的java文件是:

import java.util.Scanner;
public class crc
{
    public static void main(String args[])
    {
        int m,n,tbits,i;//m=size of data,,,,n=size of generator,,,,tbits= total size of data after the zeros have been appended.
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the size of data");
        m=sc.nextInt();
        int msg[] = new int[m];
        System.out.println("Enter the binary values");
        for(i=0;i<m;i++)
        {
            msg[i]=sc.nextInt();
        }
        System.out.println("Enter the size of generator");
        n=sc.nextInt();
        int gen[] = new int[n];
        System.out.println("Enter the binary values");
        for(i=0;i<n;i++)
        {
            gen[i]=sc.nextInt();
        }

        System.out.println("The data bits are");
        for(i=0;i<m;i++)
        {
            System.out.print(msg[i]);
        }
        System.out.println();
        System.out.println("The generator bits are");
        for(i=0;i<n;i++)
        {
            System.out.print(gen[i]);
        }
        System.out.println();

        tbits=m+n-1;
        int apmsg[]=new int[tbits]; //append zeros
        int rem[]=new int[tbits];   //findind remainder
        int tcode[]=new int[tbits]; //received data
        for(i=0;i<m;i++)
        {
            apmsg[i]=msg[i];    //appended msg
        }
        System.out.println("The data after appending zeros");
        for(i=0;i<apmsg.length;i++)
        {
            System.out.print(apmsg[i]);
        }
        System.out.println();
        for(i=0;i<apmsg.length;i++)
        {
            rem[i]=apmsg[i];    //copy to remainder
        }
        rem = calCRC(apmsg,gen,rem);    //calculate the crc and store in remaider

        for(i=0;i<rem.length;i++)
        {
            rem[i]=(apmsg[i]^rem[i]);
        }

        System.out.println("The crc code");
        for(i=0;i<rem.length;i++)
        {
            System.out.print(rem[i]);
        }
        System.out.println();

        //error detection

        System.out.println("Enter the recived crc code");
        for(i=0;i<tbits;i++)
        {
            tcode[i]=sc.nextInt();      //received data after transmitting
        }
        System.out.println("The recieved data is:");
        for(i=0;i<tbits;i++)
        {
            System.out.print(tcode[i]);     //received data after transmitting
        }
        System.out.println();
        for(i=0;i<tbits;i++)
        {
            rem[i]=tcode[i];    //copy to remainder
        }
        rem=calCRC(tcode,gen,rem);  //calculate crc
        for(i=0;i<rem.length;i++)
        {
            if(rem[i]!=0)       //if remainder is not zero error
            {
            System.out.println("Error");
            break;
            }
            if(i==rem.length-1)
            {
            System.out.println("Correct data");
            }
        }
    }

    static int[] calCRC(int apmsg[],int gen[],int rem[])
    {
        int i, c=0;
        while(true)
        {
            for(i=0;i<gen.length;i++)
            {
            rem[c+i]=(rem[c+i]^gen[i]);
            }
            while(rem[c]==0 && (c!=rem.length-1))
            {
            c++;
            }
            if((rem.length-c)<gen.length)
            break;
        }
        return(rem);
    }
}
java cmd compiler-errors javac
1个回答
0
投票

尝试在管理员模式下运行命令行javac

© www.soinside.com 2019 - 2024. All rights reserved.