Question

*1.3 (Display a pattern) Write a program that displays the following pattern: Sample Run for Exercise01 03 command javac Exercise 03.java Compiled successful command java Exercise01.03 AA A A V V J J command 1.4 (Print a table) Write a program that displays the following table: Sample Run for Exerciseo1 04 command javac Exercise 04. java Compiled successful command java Exercisea1 04 a 2 a 3 27 16 command 1.10 (Average speed in miles) Assume a runner runs 14 kilometers in 45 minutes and 30 seconds. Write a program that displays the average speed in miles per hour. (Note that 1 mile is 1.6 kilometers 1.11 (Population projection) The U.S. Census Bureau projects population based on the following assumptions: One birth every 7 seconds One death every 13 seconds One new immigrant every 45 seconds Write a program to display the population for each of the next five years. Assume the current population is 312,032,486 and one year has 365 days. Hint: In Java, if two integers perform division, the result is an integer. The fractional part is truncated. For example, 5 /4 is 1 (not 1.25) and 10/4 is 2 (not 2.5). To get an accurate result with the fractional part, one of the values involved in the division must be a number with a decimal point. For example, 5.0/4 is 1.25 and 10 4.0 is 2 5.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Exercise 01_03:

public class Exercise01_03 {
    public static void main(String args[])
    {
        //Printing to form the pattern
        System.out.println("    J     A     V     V     A");
        System.out.println("    J    A A     V   V     A A");
        System.out.println("J   J   AAAAA     V V     AAAAA");
        System.out.println(" J J   A     A     V     A     A");
    }
}


Output:

Exercise 01_04:

public class Exercise01_04 {
    public static void main(String args[])
    {
        int a;
        System.out.println("a      a^2    a^3");
        for(a = 1; a <= 4; a++)//Displaying a, a^2, a^3
            System.out.println(String.format("%s %8s %6s", a, (int)Math.pow(a, 2), (int)Math.pow(a, 3))); //Math.pow(a, 2) raises a to the power of 2
        //(int) converts data to integer type
    }
}


Output:

Exercise 01_10:

public class Exercise01_10 {
    public static void main(String args[]){
        int minutes = 45, seconds = 30;
        double distance = 14.0, dist_In_1_hr, dist_In_miles;
        seconds += minutes * 60; //Calculating total seconds
        dist_In_1_hr = 3600 * distance / seconds; //Distance in km in one hour
        dist_In_miles = dist_In_1_hr / 1.6; //distance in miles
        System.out.println(String.format("The average speed in miles = %.2f mph.", dist_In_miles));
    }
}


Output:

Output-Exercise01 (run) ル The average speed in miles 11.54 mph BUILD SUCCESSFUL (total time: 0 seconds)

Exercise 01_11:

public class Exercise01_11 {
    public static void main(String args[]){
        int i;
        double births, deaths, immigrants, final_popu = 312032486.0, popu;
        births = (365 * 24 * 3600) / 7.0; //Total births in a year
        deaths = (365 * 24 * 3600) / 13.0; //Total deaths in a year
        immigrants = (365 * 24 * 3600) / 45.0; //Total immigrants in a year
        popu = births + immigrants - deaths; //Population increase in a year
        for(i = 1; i <= 5; i++)
        {
            final_popu += popu; //Population at the end of each year
            System.out.println("Year " + i + ": " + (long)Math.ceil(final_popu)); //Population comes in whole number
            //Converting to long to display as whole number
            //Taking ceiling value of the population
        }
    }
}


Output:

Output-Exercise01 (run) x Year 1: 314812583 Year 2: 317592680 Year 3: 320372777 Year 4 323152873 Year 5 325932970 BUILD SUCCE

Add a comment
Know the answer?
Add Answer to:
Write a program that displays the following pattern: Write a program that displays the following table:...
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
  • Need this done is java program coding in the simplest way possible. (Average speed in kilometers)...

    Need this done is java program coding in the simplest way possible. (Average speed in kilometers) Assume a runner runs 24 miles in 1 hour, 40 minutes, and 35 seconds. Write a program that displays the average speed in kilometers per hour. (Note that 1 mile is 1.6 kilometers.) 1.12

  • C++ (i) Write a program that displays the following pattern: * *** ***** ******* ***** ***...

    C++ (i) Write a program that displays the following pattern: * *** ***** ******* ***** ***    * (ii) Katy bought 750 shares of stock at a price of $35.00 per share. She must pay her stockbroker a 2 percent commission for the transaction. Write a program that calculates and displays the following: The amount paid for the stock alone (without the commission) The amount of the commission) The total amount paid (stock plus commission) (iii) Write a program that...

  • java programming: Write a program that displays the following pattern (note you will need to use...

    java programming: Write a program that displays the following pattern (note you will need to use the escape sequences we learned in class to do this) &&&&&& & & & & & & & & &&&&&&

  • USING PYTHON LANGUAGE. QUESTION I: Write a program that displays the following table: a a^2 a...

    USING PYTHON LANGUAGE. QUESTION I: Write a program that displays the following table: a a^2 a 3 a14 1 1 1 1 2 4 8 16 3 9 27 81 4 16 64 256 QUESTION II: An approximate value of a number can be computed using the following formula: 7 ) Write a program that displays the result of 4 X + 7 • H) and 4 X - 를 7 tis). 9 QUESTION III: Write a program that prompts...

  • Write the PYTHON code that displays the following numbers: The program should have a header that...

    Write the PYTHON code that displays the following numbers: The program should have a header that displays "Number   Doubled Tripled" above the start of the numbers. If putting all numbers on the same line, then they will need to be separated so you can see he individual number.(https://www.programiz.com/python-programming/methods/built-in/print) The program should display Every whole number from 1 through 35. The program should display that number doubled. The program should also display that number tripled. Make a working version of this...

  • Write a function (NOT a complete program) that displays the following picture. Use nested for loops...

    Write a function (NOT a complete program) that displays the following picture. Use nested for loops inside of the program. ||#|@|#|(a) | # | @ # | @ #|(a) | # | @ You do not need to ask the user for input and can assume that there are only 6 columns

  • Write a Java application that displays the following output pattern: Thus, there are+signs everywhere except the...

    Write a Java application that displays the following output pattern: Thus, there are+signs everywhere except the diagonal, which has". "signs. There are no blank characters. Requirements and Restrictions: The number of lines and the number of characters per line, i.e. the size of the square pattern and line argument. For example, the size of the above square is 11 and it is specified through the following compile and execute commands: e >javac PrintPattern.java > java PrintPattern 11 Your program should...

  • Write a C program that reads a sequence of numbers and display a message 1. The...

    Write a C program that reads a sequence of numbers and display a message 1. The numbers a re red from the standard input. 2. The first number is the length of the sequence (n) followed by n numbers. 3. If n is 0 or negative, the program displays the message "Error_1" followed 4. If the length is shorter than n, it displays "Error_2" followed by a new line 5. The program inspects the list and display one of the...

  • java Fill in the blanks to complete the following recursive program. It shou print a pattern...

    java Fill in the blanks to complete the following recursive program. It shou print a pattern like the one below. using System.out.println. Assume you have method String nspaces(n) which returns a string containing n spaces. You should not write nspaces.) The pattern below is of size 3. The first line has one space before the while the middle line has 3 spaces before the .. The program should work for any positive size. 3 public static gt ( if( }...

  • java program: Write a program which displays the following list on the screen and asks the...

    java program: Write a program which displays the following list on the screen and asks the user to enter either 1 or 2 and perform one of the operations based on the user’s input. If the user enters any other character other than 1 or 2 then display “wrong choice”. LIST OF OPERATIONS 1. Buzz Number                      2. Consecutive Odd numbers Note: A BUZZ number is a number which either ends with 7 or is divisible by 7. Sample input 27...

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
ADVERTISEMENT