Question

Using java write a program that takes a single, positive integer, n as a command-line argument....

Using java write a program that takes a single, positive integer, n as a command-line argument. The program should then plot n evenly spaced points around a circle
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

class Circle{
// function to print circle pattern
static void printCircle(int radius){
// dist represents distance to the center
double dist;
// for horizontal movement
for(int i=0;i<=2*radius;i++){
// for vertical movement
for(int j=0;j<=2*radius && i%2==0;j++){ //For even spaces we included "i%2==0" condition too
dist=Math.sqrt((i-radius)*(i-radius)+(j-radius)*(j-radius));// dist should be in the range (radius - 0.5)
if(dist>radius-0.3 && dist<radius+0.3)// and (radius + 0.5) to print stars(*)
System.out.print("*");
else
System.out.print(" ");
}
System.out.print("\n");
}
}

public static void main(String[] args){
int radius=Integer.parseInt(args[0]); //Converting command line string input to integer
printCircle(radius);
}
}

Output:-

Thank you

Add a comment
Know the answer?
Add Answer to:
Using java write a program that takes a single, positive integer, n as a command-line argument....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write Java program that takes an integer N from the command line and creates N by...

    Write Java program that takes an integer N from the command line and creates N by N boolean array a[][] such that a[i][j] is true if i and j are relatively prime (have no common factors) and false otherwise. print the output using * to represent true and a space to represent false and include row and column numbers. (use sieving)

  • Part 1: Write a C program that takes an integer command line argument n, spawns n...

    Part 1: Write a C program that takes an integer command line argument n, spawns n processes that will each generate a random numbers between -100 and 100, and then computes and prints out the sum of these random numbers. Each process needs to print out the random number it generates. name the program 003_2.c

  • java) write a program that takes command line argument and compute the average of their maximum...

    java) write a program that takes command line argument and compute the average of their maximum and minimum. make sure there are command line arguments being passed before you attempt to compute anything

  • Write a C program called test that takes one command line argument, an integer N. When...

    Write a C program called test that takes one command line argument, an integer N. When we run test: ./test N the program will do this: the parent process forks N child processes each child process prints its process ID, exits the parent process waits for all child processes to exit, then exits

  • Java!!! Write a program that takes a file name as its command line argument. It assumes...

    Java!!! Write a program that takes a file name as its command line argument. It assumes the file is a binary data file and checks the first 4 bytes of the file to see whether they contain the integer −889275714. It outputs “yes” or “no” or an error message if there was an IOException generated. (Trivia question: Why test for that particular value? Hint: Try it on several .class files.)

  • How do I write a C program called binary that takes a single command line argument,...

    How do I write a C program called binary that takes a single command line argument, and integer, in decimal, and prints out the binary representation of the number with 64 bits. The argument must be stored as a long. Use atol to convert the command line argument. Include a function char *binary(long n, char *b) { ... } that stores the binary representation in the string b with '0's and '1's. It is the responsibility of the calling program...

  • I need help with a java program Write a program Enigma that takes a single String...

    I need help with a java program Write a program Enigma that takes a single String as a command line argument. Enigma should read the file specified by the String argument, add 5 to each byte, and leave the altered data values in a file whose name is the command line argument. Note that this "updating in place" is the most difficult part of this lab: java Enigma sophie.dat should read file sophie.dat, and upon completion, leave the modified data...

  • Write a C++ program that accepts one command line argument which is an integer n between 2 and 4 inclusive. Generate 60...

    Write a C++ program that accepts one command line argument which is an integer n between 2 and 4 inclusive. Generate 60 random integers between 1 and 49 inclusive and store them in a 5 by 12 two dimensional integer array (e.g.,int a[5][12];). Use pthread to create n threads to square all 60 array elements. You should divide this update task among the n threads as evenly as possible. Print the array both before and after the update separately as...

  • [loops] Write a java program that accepts a number, as command line argument and prints out...

    [loops] Write a java program that accepts a number, as command line argument and prints out “Hello, World!” that many times using a for loop. E.g. if the input number is 3, the program outputs: Hello, World! Hello, World! Hello, World! Keep it simple, please use the argument, not interact with the console. Thanks

  • Help please Write a program named one.c that takes a single command-line argument, the name of...

    Help please Write a program named one.c that takes a single command-line argument, the name of a file. Your program should read all the strings (tokens) from this file and write all the strings that are potentially legal words (the string contains only upper-case and lower-case characters in any combination) to the file words. Your program should ignore everything else (do not write those strings anywhere 1. As an example, running /a.out dsia would result in the generation of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT