Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Syntax error hamming code

  1. #1
    Junior Member
    Join Date
    Dec 2020
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Syntax error hamming code

    hey guys i did some code to do hamming and I have a syntax error in my code and I need to correct it and I don't know how to resolved this is my code

    import java.lang.Math;

    char [] GenerateSequence(int length)
    int[] numbers = new int[legnth];
    for (int i = 0; i < numbers.length; i++) {
    if (Math.random() > 0.5) {

    numbers[i] = 1;
    else
    numbers[i] = 0;
    }
    return numbers;
    }
    }

    char CalculateNbControlBits(int length){

    int nextpower2=1;
    int p=1;
    Nombredebit=0;
    for (int i = 0; i < numbers.length; i++) {
    {
    if(p == nextpower2)
    {
    Nombredebit++;

    nextpower2 = nextpower2 * 2;
    }

    p++;
    }

    return Nombredebit;
    }
    }


    void AddControlBits(char info[], int length, int nbControlBits)
    {
    for (int i = 0; (i < numbers.length()); i++) {
    if ((numbers[i] == -1)) {
    boolean impair = nbControlBits(numbers, (i + 1));
    if (pair) {
    numbers[i] = 0;
    }
    else {
    numbers[i] = 1;
    }

    }

    }

    return numbers;
    }

    void CalculateControlBits(char codeWord[], int length, int nbControlBits)
    {
    static int[] calculation(int codeword, int Nombredebit)

    for (int i = 0; i < Nombredebit; i++) {
    int x = (int)Math.pow(2, i);
    for (int j = 1; j < codeword.length; j++) {
    if (((j >> i) & 1) == 1) {
    if (x != j)
    codeword[x] = codeword[x] ^ codeword[j];
    }
    }

    }

    return codeword;

    }
    char [] GenerateErrorsInCodeWord (char codeWord[], int lengthCodeWord, double prob) {
    int[] lengthCodeWord = new int[legnth];

    for (int i = 0; i < numbers.length; i++) {
    if (Math.random() < prob) {
    lengthCodeWord++;
    if (numbers[i] == 0)
    numbers[i] = 1;
    else
    numbers[i] = 0;
    }

    return numbers;
    }
    }


    char [] CorrectCodeWord (char codeWord[], int lengthCodeWord)
    {
    int power2=1;
    int sum=0;
    while(power2 < numbers.length)
    {
    sum=sum+power2;
    power2=power2*2;
    }
    if(sum==0)

    System.out.println(" pas d erreur");
    else
    {

    System.out.println(" erreur dans "+sum);
    if(numbers[sum-1]==0)
    numbers[sum-1]=1;
    else
    numbers[sum-1]=0;
    }
    return numbers;
    }


    boolean CompareTwoSequence(char sequence1, char sequence2)
    {

    int Erreur = 0;

    if (sequence1[i] != sequence2[i])

    for(int i = 0; i < sequence1[i]; i++)
    {
    if(sequence1[i] != sequence2[i])
    {
    Erreur++;
    }
    }

    return Erreur;
    }
    }
    class numbers {

    public boolean VERBOSE = false;


    private int vecteur_information;

    private int vecteur_nbErreurs;

    private int vecteur_nbBitsControle;

    private int lengthTrames;


    public numbers(int pro_lengthTrames) {
    this.lengthTrames = pro_lengthTrames;
    this.vecteur_nbErreurs = new int ();
    this.vecteur_nbBitsControle = new List<int>();
    }


    public final void initialisnumbers(int nbBits) {
    this.vecteur_information = new List<int>();
    for (int i = 0; (i < nbBits); i++) {
    Random random = new Random();
    this.vecteur_information.Add(random.Next(0, 2));
    }

    }

    public final void miseEnTrames() {
    int nbTrames = (this.vecteur_information.Count() / this.lengthTrames);

    int longueurDerniereTrame = (this.vecteur_information.Count() % this.lengthTrames);
    int trameInformation;
    for (int i = 0; (i < nbTrames); i++) {
    trameInformation = this.vecteur_information.GetRange((i * this.lengthTrames), this.lengthTrames);
    this.pilote(trameInformation);
    }


    if ((longueurDerniereTrame != 0)) {a
    trameInformation = this.vecteur_information.GetRange((nbTrames * this.lengthTrames), longueurDerniereTrame);
    this.pilote(trameInformation);
    }

    }

    public final void pilote(int trameInformation) {
    int nbBitControl = 0;
    int nbErreurCan = 0;
    int nbErreurRecue = 0;
    int copieInformation = new int (trameInformation);

    Trame objTrame = new Trame();

    if (this.VERBOSE) {
    Console.Write("Trame information : ");
    Trame.afficherMessage(copieInformation);
    }


    int mesgEncode = objTrame.encodageHamming(copieInformation, ref nbBitControl);
    this.vecteur_nbBitsControle.Add(nbBitControl);
    if (this.VERBOSE) {
    Console.WriteLine(("Nb bit control : " + nbBitControl));
    Trame.afficherMessage(mesgEncode);
    }

    int mesgAvecControle = objTrame.ajouterBitDeControl(mesgEncode);
    if (this.VERBOSE) {
    Trame.afficherMessage(mesgAvecControle);
    }


    int mesgRecu = objTrame.passageCanal(mesgEncode, (1 / 25), ref nbErreurCan);
    if (this.VERBOSE) {
    Trame.afficherMessage(mesgRecu);
    System.out.println(("Nb Erreurs canal : " + nbErreursCan));
    }


    int mesgCorrige = objTrame.corrigerErreur(mesgRecu);
    if (this.VERBOSE) {
    Trame.afficherMessage(mesgCorrige);
    }


    int informationRecue = objTrame.extraireInformation(mesgCorrige);
    if (this.VERBOSE) {
    Trame.afficherMessage(informationRecue);
    }


    nbErreurRecue = objTrame.calculerNbErreurs(trameInformation, informationRecue);
    this.vec_nbErreurs.Add(nbErreursRecues);
    if (this.VERBOSE) {
    System.out.println(("Nb err entre trame recue et envoyee : " + nbErreursRecues));
    System.out.println(" ===================================== ");
    }

    }

    public final void calculeStat(int lengthTrames, int longueurMessage) {
    System.out.println(" =============== Statistiques ================ ");
    System.out.println(("Longueur des trames : " + this.lengthTrames));
    System.out.println("Vecteur du nb d\'erreurs : ");
    Trame.afficherMessage(this.vecteur_nbErreurs);
    System.out.println("Vecteur du nb de bits de controle : ");
    Trame.afficherMessage(this.vecteur_nbBitsControle) ;
    double moyenneErreurs = (this.vecteur_nbErreurs.Sum() / this.lengthTrames);
    double moyenneBitsControle = this.vecteur_nbBitControl.Average();
    System.out.println("Moyenne nb erreurs : ");
    System.out.println(moyenneErreurs);
    System.out.println("Moyenne nb de bits de controle : ");
    System.out.println(moyenneBitsControle);
    }
    }
    class Program {

    static void Main(string[] args) {
    int lengthTrames;
    int lengthnumbers= 3100;
    for (lengthTrames = 5; (lengthTrames
    < (lengthnumbers / 5)); lengthTrames += 5) {
    numbers objnumbers = new numbers(lengthTrames);
    objnumbers.initialisnumbers(1000);
    objnumbers.miseEnTrames();
    objnumbers.calculeStat(lengthTrames, lengthnumbers);
    }

    for (
    ; (lengthTrames < lengthnumbers); lengthTrames = (lengthTrames * 2)) {
    numbers objnumbers= new numbers(lengthTrames);
    objnumbers.initialisnumbers(1000);
    objnumbers.miseEnTrames();
    objnumbers.calculeStat(lengthTrames, lengthnumbers);
    }

    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Syntax error hamming code

    I have a syntax error
    Please copy the full text of the error message and paste it here. It has important info about the error.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    http://www.java-forums.org/misc.php?do=bbcode#code
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. syntax error
    By juliaannn in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 1st, 2014, 03:40 AM
  2. Syntax error!!!
    By Gerock7 in forum What's Wrong With My Code?
    Replies: 23
    Last Post: April 22nd, 2014, 07:14 PM
  3. Syntax error
    By Kez in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 19th, 2014, 04:48 PM
  4. [SOLVED] Read strings, calculate Hamming Distance
    By dianac in forum Object Oriented Programming
    Replies: 11
    Last Post: April 25th, 2013, 01:52 AM
  5. java using textpad. Atm code not having any syntax error but runs funny
    By bukasmayor in forum What's Wrong With My Code?
    Replies: 8
    Last Post: January 28th, 2013, 07:55 AM