Sunday, February 2, 2020

PROGRAMMING IN JAVA WEEK 1 ASSIGNMENT SOLUTION

Here I have pasted only the answer and not the complete program so please paste the stuff carefully, I have tried to copy the whole program but it is not selecting the whole program at once.

QUESTION 1 :

//Calculate the perimeter 
perimeter=2*Math.PI*radius;

//Calculate the area
area=Math.PI*radius*radius;

if(area>0&&perimeter>0)
        {
          System.out.println(perimeter);
          System.out.print(area);
        }

else
        {
          System.out.print("please enter non zero positive number");
        }

QUESTION 2:

//Use if...else ladder to find the largest among 3 numbers and store the largest number in a variable called result.

if(x>y&&x>z)
          result=x;

else if(y>x&&y>z)
          result=y;
          
        else 
          result=z;
          
        System.out.print(result);

QUESTION 3 :

//Use for or while loop do the operation

for(int i=0; i<n*2; i=i+2)
        {
          if(i%3==0)
            sum=sum+i;
        }

System.out.print(sum);

QUESTION 4:

//Use while loop check the number is Armstrong or not.

int i=n;
int count=0; 
while(i>0)
        {
          i=i/10;
          count++;
        }
i=n;
int rem;
int sum=0;
while(i>0)
        {
          rem=i%10;
          i=i/10;
          int a=rem;
          for(int j=0; j<count-1; j++)
            rem=rem*a;
          sum=sum+rem;
        }
          
//store the output(1 or 0) in result variable.
if(sum==n)
          result=1;
else
          result=0;

System.out.print(result);

QUESTION 5:

 //Initialize maximum element as first element of the array.
   //Traverse array elements to get the current max.

int mm=arr[0];
int sum=0;
for(i=0; i<arr.length; i++)
    {
      sum=sum+arr[i];
      if(arr[i]>mm)
        mm=arr[i];
    }
   //Store the highest mark in the variable result.
result=mm;
   //Store average mark in avgMarks.
mark_avg=sum/arr.length;

System.out.println(result);
System.out.print(mark_avg);

4 comments:

  1. Strange "water hack" burns 2lbs overnight

    Over 160k men and women are utilizing a easy and secret "liquids hack" to drop 1-2lbs each and every night as they sleep.

    It is scientific and works with everybody.

    This is how to do it yourself:

    1) Grab a drinking glass and fill it up with water half the way

    2) Now follow this awesome hack

    and you'll become 1-2lbs skinnier the next day!

    ReplyDelete