you are given a list of n integers and another number k . if the sum of the all given integers is divisible by k, then print 1 ,else 0. using java
Answers
Explanation:
class sum
{
public static void main(String arg[])
{
int n,sum=0,i=0, k=0;
Scanner sc=new Scanner(System.in);
Scanner sc1=new Scanner(System.in);
System.out.println("Enter how many numbers you want sum");
n=sc.nextInt();
int a[]=new int[n];
System.out.println("Enter the "+n+" numbers ");
while(i<n)
{
System.out.println("Enter number "+(i+1)+":");
a[i]=sc.nextInt();
sum+=a[i];
i++;
}
System.out.println("sum is ="+sum);
k=sc1.nextInt();
If
{
sum/k==0;
System.out.println("1");
} else
System.out.println("0");
}
}