Java Program to implement decimal checksum

//java program for decimal checksum
import java.util.*;
import java.io.*;
class DjCheck1
{
int i,j,k,l,m;
int ans=0,ans1=0;
//String pck="";
public void checksum()
{
System.out.println("How many message you want to send ?");
Scanner s=new Scanner(System.in);
i=s.nextInt();
int msg[][]=new int[i][8];
Scanner s1=new Scanner(System.in);
for(j=0;j<i;j++)
{
System.out.println(" Enter your decimal value: ");
for(k=0;k<8;k++)
{
msg[j][k]=s1.nextInt();
}
}
for(l=0;l<i;l++)
{
ans=0;ans1=0;
System.out.print("[ ");

for(m=0;m<8;m++)
{

System.out.print(msg[l][m]+" , ");
ans+=msg[l][m];
ans1=0-ans;
}
System.out.print(ans1+" ]");
if(ans+ans1==0)
{
System.out.print(" no error.");
}
else
{
System.out.print(" error in your message.");
}
System.out.println();
}
}
}
class DjCheckSum
{
public static void main(String args[])
{
int ch;
DjCheck1 obj=new DjCheck1();
obj.checksum();
}
}
/*output
[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , -36 ] no error.
[ 9 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , -30 ] no error.
*/

Comments

Post a Comment

Popular posts from this blog

Java Program to implement binary checksum

Java Program for block parity

Welcome Guide to Swift 5 Escaping String