Write a program that accepts the radius of a circle in the client side of a program and compute the area and perimeter in the server side program

Write a program that accepts the radius of a circle in the client side of a program and compute the area and perimeter in the server side program and return the values to the client program.

// Client   import java.io.*; import java.net.*;  public class Client {             public static void main(String[] args) throws IOException{                 Socket s = new Socket("localhost",1234);                 BufferedReader br;                 PrintStream ps;   String str;                System.out.println("Enter Radius  :");                 br=new BufferedReader(new InputStreamReader(System.in));    ps=new PrintStream(s.getOutputStream());                ps.println(br.readLine());    br=new BufferedReader(new InputStreamReader(s.getInputStream()));                str=br.readLine();                System.out.println("Area of the circle is : "+str);                 br.close();                 ps.close();            } } 
// Server  import java.io.*; import java.net.*;  class Server {       public static void main(String[] args){           try {           ServerSocket ss = new ServerSocket(1234);                  System.out.println("Waiting for Client Request");                   Socket s=ss.accept();                   BufferedReader br;                   PrintStream ps;                   String str;                   br=new BufferedReader(new InputStreamReader(s.getInputStream()));                   str=br.readLine();                   double r=Double.parseDouble(str);                   double area=3.14*r*r;                   ps=new PrintStream(s.getOutputStream());                   ps.println(String.valueOf(area));                   br.close();                   ps.close();                   s.close();                   ss.close();        }           catch(Exception e)           {                       System.out.println(e);           }  } }  

how to add perimeter of a circle

How to find Maximum perimeter of rectangle in a grid with obstacles? (Dynamic Programming)

Can someone tell me what am I doing wrong?

Problem: https://codeforces.com/contest/22/problem/B

Editorial: https://codeforces.com/blog/entry/507 ( I followed the DP solution O((n*m)^2) )

My approach: rectangle with coordinates (x1, y1, x2, y2) is correct if and only if rectangles (x1, y1, x2-1, y2) and (x1, y1, x2, y2-1) are correct, and board[x2][y2] = ‘0’.

If it is correct then find it’s perimeter and if it’s greater then answer then answer=perimeter ie ans=max(ans,dp[i][j][p][q])

so dp[ i ][ j ][ i ][ j ]=1 for all i,j when v[i][j]==0. Because from point p1 to point p1, ie the same point always have a perimeter is the base case.

signed main(){     int r,c;cin>>r>>c;     vector<vi> v(r,vi(c));//2d array v[r][c]     bool dp[25][25][25][25]={false};//i,j to p,q     for(int i=0;i<r;i++){         string s;cin>>s;         for(int j=0;j<c;j++){             v[i][j]=(s[j]-'0');             if(v[i][j]==0)dp[i][j][i][j]=true;         }     }     int ans=-1;     for(int i=0;i<r;i++){         for(int j=0;j<c;j++){             for(int p=i;p<r;p++){                 for(int q=j;q<c;q++){                     //i,j to p,q , 0,0 0,2, afrom 1 to p, b from 1 to q                     if(!(i==p && j==q)){                         if(p-1>=0 && q-1>=0)                             dp[i][j][p][q]=(dp[i][j][p-1][q] && dp[i][j][p][q-1] && (v[p][q]==0));                         if(dp[i][j][p][q]==true){                             ans=max(ans,2*(p-i+q-j+2));                         }                     }                 }             }         }     }     cout<<ans; } 

Island Perimeter

The task is taken from leetcode

You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water.

Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells).

The island doesn’t have “lakes” (water inside that isn’t connected to the water around the island). One cell is a square with side length 1. The grid is rectangular, width and height don’t exceed 100. Determine the perimeter of the island.

Example:

Input:

[[0,1,0,0],  [1,1,1,0],  [0,1,0,0],  [1,1,0,0]] 

Output: 16

Explanation: The perimeter is the 16 yellow stripes in the image below: enter image description here

My solution

/**  * @param {number[][]} grid  * @return {number}  */ var islandPerimeter = function(grid) {   const getWaterNeighborAt = position => {     if (!grid[position.y][position.x]) { return 0; }      const north = position.y - 1 < 0 ? true : grid[position.y - 1][position.x] === 0;     const east = position.x + 1 >= grid[0].length ? true : grid[position.y][position.x + 1] === 0;     const south = position.y + 1 >= grid.length ? true : grid[position.y + 1][position.x] === 0;     const west = position.x - 1 < 0 ? true : grid[position.y][position.x - 1] === 0;      return north + east + south + west;   };   let perimeter = 0;   grid.forEach((row, y) => {     row.forEach((_, x) => {       perimeter += getWaterNeighborAt({x, y});     });   });   return perimeter; }; 

How to print the perimeter of a square using asterisks on Python?

I want to write a program that asks the user to enter the length of the side of a square then display a square composed of asterisks along its perimeter, such as shown below: enter image description here

enter image description here

My coding attempt is as follows:

answer = input("Enter the length of square: ") length = int(answer)  for i in range(1, length+1):   if(i == 1 or i == length):     for k in range(1, length+1):       print("*", end="")   else:     for k in range(1, length+1):       if(k == 1):         print("*", end="")       elif(k < length):         print(" ", end="")       else:         print("*") 

But the output is not quite what I want. For example, if I enter 5 as the length of the side, I get the following output:

enter image description here

And note that I’m still a beginner with Python so I don’t know anything beyond loops so far (in case there’s an alternative way without the use of a for loop). Does anyone know what’s wrong with my code?

Does Magic Circle prevent non-weapon melee attacks across the circle’s perimeter?

The Magic Circle spell creates a circle that protects against certain types of creatures, and states:

[A creature of one of those types] can’t willingly enter the Cylinder by nonmagical means. If the creature tries to use teleportation or interplanar travel to do so, it must first succeed on a Charisma saving throw.

[A creature of one of those types] has disadvantage on Attack rolls against Targets within the Cylinder.

Such a creature tries to make an unarmed melee attack against a creature fully within the cylinder. What happens?

  1. They cannot do so, because part of their body entering the cylinder is treated the same as their whole body entering the cylinder.
  2. They can do so, but have disadvantage. They are not trying to “enter” the cylinder, just briefly extending their body into it.

Question about determining area of a right triangle, perimeter given, hypotenuse value given in terms of one of the legs.

Hello I have a question about a difficult problem.
The problem states:
Right Triangle- perimeter of 84, and the hypotenuse is 2 greater than the other leg. Find the area of this triangle.
I have tried different methods of solving this problem using Pythagorean Theorem and systems of equations, but cannot find any of the side lengths or the area of the right triangle. I looked for similar problems on StackExchange and around the internet, but could not find anything.
Does anyone know anything that could help find the side lengths of the triangle and the area as well?

Thanks,
William.