Can anyone please help me to solve this question for java W
Solution
//Calculation of checksum
 String sum = “0000”;
 for(int i=0;i<hex.length;i++){
 int temp = Integer.parseInt(sum,16) + Integer.parseInt(hex[i],16);
 sum = Integer.toHexString(temp);
 }
 if(sum.length()>4){//Wrapping if length of sum is > 4
 int n = sum.length()-4;
 int temp = Integer.parseInt(sum.substring(0,n),16) + Integer.parseInt(sum.substring(n),16);
 sum = Integer.toHexString(temp);
 }
 int complement = Integer.parseInt(“FFFF”,16) – Integer.parseInt(sum,16); //Finding the 1s complement
 sum = Integer.toHexString(complement);
 System.out.println(“The checksum is: “+sum);
 
 System.out.println(“*********RECEIVER*********”);
 System.out.print(“Enter the word: “);
 input = sc.nextLine();
 
 //Calculation of hex string
 if(input.length()%2 == 0){ //Even length input
 hex = new String[input.length()/2];
 for(int i=0;i<hex.length;i++)
 hex[i] = Integer.toHexString(input.charAt(2*i))+Integer.toHexString(input.charAt(2*i+1));
  }else{//odd length input
 hex = new String[input.length()/2 + 1];
 hex[0] = “00”+Integer.toHexString(input.charAt(0)); //For 1st char append 00 at beginning
 for(int i=1;i<hex.length;i++)
 hex[i] = Integer.toHexString(input.charAt(2*i-1))+Integer.toHexString(input.charAt(2*i));
  }
 System.out.println(“The hex strings for the input are: “);
 for(int i=0;i<hex.length;i++)
 System.out.print(hex[i]+” “);
 System.out.println();
 
 //Calculation of checksum
 sum = “0000”;
 for(int i=0;i<hex.length;i++){
 int temp = Integer.parseInt(sum,16) + Integer.parseInt(hex[i],16);
 sum = Integer.toHexString(temp);
 }
 if(sum.length()>4){//Wrapping if length of sum is > 4
 int n = sum.length()-4;
 int temp = Integer.parseInt(sum.substring(0,n),16) + Integer.parseInt(sum.substring(n),16);
 sum = Integer.toHexString(temp);
 }
 complement = Integer.parseInt(“FFFF”,16) – Integer.parseInt(sum,16); //Finding the 1s complement
 sum = Integer.toHexString(complement);
 System.out.println(“The checksum is: “+sum);
 
 if(sum.equals(“0”)) System.out.println(“Checksum is valid.”);
 else System.out.println(“Checksum is invalid.”);
 }
 }
 
 
 
 /*Output
 **********SENDER**********
 Enter the word: KJSCE
 The hex strings for the input are:
 004b 4a53 4345
 The checksum is: 721c
 *********RECEIVER*********
 Enter the word: KJSCEOP
 The hex strings for the input are:
 004b 4a53 4345 4f50
 The checksum is: 22cc
 Checksum is invalid.


