Question

In Java, write a program called SCATTEREDLNS that prints out lines that contain a random number...

In Java, write a program called SCATTEREDLNS that prints out lines that contain a random number of “x” characters (between 5 and 20 inclusive) until it prints a line that contains 16 or more characters. For example, it might look something like this

xxxxxxx 
xxxxxxxxxxxxxxx 
xxxxxxxxxxxx 
xxxxxxxxxxxxxx 
xxxxxx 
xxxxxxxxxxx 
xxxxxxxxxxxxxxxxx
0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

import java.lang.Math; // headers MUST be above the first class
import java.util.Random;
public class HelloWorld
{
// arguments are passed using the text field below this editor
public static void main(String[] args)
{
int nos=0;
Random randomGenerator = new Random();
while(nos!=16)
{
nos = 5 + randomGenerator.nextInt(15);
for(int i=1;i<=nos;i++)
System.out.print("x");
System.out.println();
}
  
}
}

Add a comment
Know the answer?
Add Answer to:
In Java, write a program called SCATTEREDLNS that prints out lines that contain a random number...
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
  • C++ Write a program that asks for a number and then prints as many lines as...

    C++ Write a program that asks for a number and then prints as many lines as the user inputs. Each line contains as many pairs of characters ("*#") as the number of this line. It should look like the right half of a pyramid. Your version of the program must print the same result as the expected output. To to this lab, you must use two do-while loops. Two exceptions: When the user inputs a number less than 1, then...

  • Write a program in java that asks a user for a file name and prints the...

    Write a program in java that asks a user for a file name and prints the number of characters, words (separated by whitespace), and lines in that file. Then, it replaces each line of the file with its reverse. For example, if the file contains the following lines (Test1.txt): This is a test Hi there Output on the console: Number of characters: 22 Number of words: 6 Number of lines: 2 Data written to the file (Test1.txt): tset a si...

  • Write a program that reads in a text file, infile.txt, and prints out all the lines...

    Write a program that reads in a text file, infile.txt, and prints out all the lines in the file to the screen until it encounters a line with fewer than 4 characters. Once it finds a short line (one with fewer than 4 characters), the program stops. For your testing you should create a file named infile.txt. Only upload your Python program, I will create my own infile.txt. Please use a while-loop BUT do not use break, Exit or Quit...

  • 2.29 Random Phone Number (Java) Write a program that creates and prints a random phone number...

    2.29 Random Phone Number (Java) Write a program that creates and prints a random phone number of the form 668-555-xxxx where xxxx is a 4-digit randomly generated number. Include the dashes in the output. Think through how you can guarantee a 4-digit number. Your output should look like: A random phone number: 678-555-1234 Given: import random number public class PhoneNumbers { //----------------------------------------------------------------- // Produces a random phone number of the form 678-555-xxxx. //----------------------------------------------------------------- } }

  • Java Programming Write a program called “LargestNumber”, that compares below three numbers and prints out the...

    Java Programming Write a program called “LargestNumber”, that compares below three numbers and prints out the largest number. Num1 = 10, Num2-15, Num3=20. 1. You must use “If/else” logical statement to compare the three numbers.

  • Write a C program called last10 that prints the last ten lines of a text file....

    Write a C program called last10 that prints the last ten lines of a text file. The program can be used from the command line with: last10 filename or last10 If there is no filename, last10 processes standard input.

  • [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

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • Write a JAVA program that has a method which accepts a string and prints it back...

    Write a JAVA program that has a method which accepts a string and prints it back to the user with all vowels replaced with *'s (multiple asterisks not '*s') with a new line after the string. The method signature should look like this: public static void replacePrint(String input)

  • Write a script that works in vim: We are given a Java program RandomTest.java that generates...

    Write a script that works in vim: We are given a Java program RandomTest.java that generates specified number of random integers in the range [0...99]. The program prints FAIL if either 0 or 99 is generated (along with a count of how many times). Otherwise it prints PASS. The program takes the number of random integers to generate as a command line argument as shown below. Note that the given results each time is is run. [an@localhost ~] java Random...

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