import java.util.Random; import java.util.Scanner; class HammingCode { static void print ( int ar [ ] ) {
Fantastic news! We've Found the answer you've been seeking!
Question:
import java.util.Random;
import java.util.Scanner;
class HammingCode
static void printint ar
for int i ; i arlength; i
System.out.printari;
System.out.println;
static int calculationint ar int r
for int i ; i r; i
int x int Math.pow i;
for int j ; j arlength; j
if j i &
if x j
arx arx arj;
System.out.printlnp x arx;
return ar;
static int generateCodeString str int M int r
int ar new intr M ;
int j ;
for int i ; i arlength; i
if MathceilMathlogi Math.logMathfloorMathlogi Math.log
ari;
else
ariintstrcharAtj;
j;
return ar;
public static void mainString args
Scanner scanner new ScannerSystemin;
Input message from the user
System.out.printEnter Data: ;
String str scanner.nextLine;
int M strlength;
int k ;
K M K
while Math.pow kM k
k;
int ar generateCodestr M k;
System.out.printlnGenerated Hamming code ;
printar;
Simulate transmission with random errors
Random random new Random;
for int i ; i arlength; i
if randomnextDouble Simulating error rate adjust as needed
ari ari; Flip the bit
System.out.printlnReceived Hamming code with errors ;
printar;
ar calculationar k;
Calculate error percentage
int errorCount ;
for int i ; i arlength; i
if ari
errorCount;
double errorPercentage double errorCount arlength ;
System.out.printlnPercentage of errors at the receiver: errorPercentage ;
scanner.close;
in this code i want to enter the number of errors from the user thenprint the percentage error at the reciever
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date: