Question

write a java program that does the following Part one Use a For loop to compute...

write a java program that does the following

Part one

  1. Use a For loop to compute the sum of all the odd numbers from 1 through 99. Your result should be labeled, and the value should be 2500.
  2. Print your name 7 times using a While loop.
  3. String dogNames[ ] = {"Sam","Buster","Fido","Patches","Gromit","Flicka"};
    Using the array defined here, print the values of the array vertically and horizontally using one For-Each loop.
  4. Reverse the logic (Nested loops: Indent text) so that the first line is indented userNum number of spaces and the subsequent lines are each indented one less space until the last value is not indented at all (‘s’ indicates one space):
    sssss5
    ssss4
    sss3
    ss2
    s1
    0
  5. String method practice:
    • Create a String variable that contains your full name
    • Repeat the following steps -- in other words, code a loop -- that repeats until you see all of the random values (hint: four boolean flags will work well here -- loop until all are true!) Also, you will use four, different predefined String methods to modify your name as indicated - see section 3.8 and 3.9 in our zyBook for examples:
      • Generate a random number between 1 and 4
      • If number is 1, replace your first name with "One" and display the result
      • If number is 2, display the length of the String variable that contains your full name
      • If number is 3, append " is a successful student!" to your full name and display the result (note there are two ways to do this so use the method; do not use the +)
      • If number is 4, display the character at index 4
  6. Part two Create an array that will hold 4 string values. Write three separate statements to store your favorite color, your favorite song, and your favorite restaurant in the array elements. I do not want you to use a loop in this logic; use hard-coded index values instead. Print *ALL FOUR* of the values of the array using individual index values. What is stored in the element you did not fill? (type your answer in a single line comment within your program)
  7. Create an array that will hold 5 string values. Use a for loop to prompt the user to enter their 5 favorite movies and store each one in a separate element of the array. Print the values of the array using a For-Each loop.
    • Modify the array for steps part two to hold 3 String values instead of what we did before. This array should be created in the main method and passed into each method when called.
  • make sure you include Javadoc comments on each method to describe 'what' the method does
0 0
Add a comment Improve this question Transcribed image text
Answer #1

package HomeworkLib;

public class Chegg_3rdMar {

   public static void main(String[] args) {
       int sum = 0;
       for (int i = 1; i < 100; i += 2) {
           sum = sum + i;
       }
       System.out.println(sum);
   }

}

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

package HomeworkLib;

public class Chegg_3rdMar {

   public static void main(String[] args) {
       String myName="Akash";
       int counter=1;
       while(counter<=7) {
       System.out.println(myName);
       ++counter;
       }
   }

}

Add a comment
Know the answer?
Add Answer to:
write a java program that does the following Part one Use a For loop to compute...
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 a simple Java program with the following naming structure: Open Eclipse Create a workspace called...

    Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called hw1 Create a project called hw1 (make sure you select the “Use project folder as root for sources and class files”) Create a class called Hw1 in the hw1 package (make sure you check the box that auto creates the main method). Add a comment to the main that includes your name Write code that demonstrates the use of each of the following basic...

  • Write a Java program to do the following with your name. This can all be done...

    Write a Java program to do the following with your name. This can all be done in the main() method. 1. Create a String variable called myName and assign your personal name to it. Use proper capitalization for a legal name. I.e. String myName = "Billy Bob"; 2. Load myName with the upper case version of itself and display the result. 3. Load myName with the lower case version of itself and display the result. 4. Capitalize the first letter...

  • Please complete the lab following the guidelines using JAVA Activity 1 Write a program called AnalyzeNumbers....

    Please complete the lab following the guidelines using JAVA Activity 1 Write a program called AnalyzeNumbers. This program will have array that holds 10 random integers from 1 to 5. Output the 10 random numbers to the screen using an enhanced for loop. This program will also have a method called frequency that takes an integer array as the parameter and it will return an array that holds the frequency of numbers. Index 0 will hold the frequency of 1,...

  • In Java Problem Description/Purpose:  Write a program that will compute and display the final score...

    In Java Problem Description/Purpose:  Write a program that will compute and display the final score of two teams in a baseball game. The number of innings in a baseball game is 9.    Your program should read the name of the teams. While the user does not enter the word done for the first team name, your program should read the second team name and then read the number of runs for each Inning for each team, calculate the...

  • java programe Write a program that prompts the user to enter in an integer number representing...

    java programe Write a program that prompts the user to enter in an integer number representing the number of elements in an integer array. Create the array and prompt the user to enter in values for each element using a for loop. When the array is full, display the following: The values in the array on a single line. The array with all of the elements reversed. The values from the array that have even numbered values. The values from...

  • ( Object array + input) Write a Java program to meet the following requirements: 1. Define...

    ( Object array + input) Write a Java program to meet the following requirements: 1. Define a class called Student which contains: 1.1 data fields: a. An integer data field contains student id b. Two String data fields named firstname and lastname c. A String data field contains student’s email address 1.2 methods: a. A no-arg constructor that will create a default student object. b. A constructor that creates a student with the specified student id, firstname, lastname and email_address...

  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • I should use the array and loop to create a java program according to the instruction,...

    I should use the array and loop to create a java program according to the instruction, but I have no idea how to do it. Introduction This lab assignment continues to give you practice using loops, particularly loops with variable termination conditions, and it also provides you an opportunity to use one-dimensional arrays. Recall that an array is used to store a collection of data. The data can be values of Java primitive data types or else objects (for instance,...

  • 3. Write Java methods to accomplish each of the following Write a method named simpleAry which...

    3. Write Java methods to accomplish each of the following Write a method named simpleAry which accepts and return nothing. It creates an array that can hold ten integers. Fill up each slot of the array with the number 113. Then, display the contents of the array on the screen. You must use a loop to put the values in the array and also to display them. Write a method named sury which accepts an array of type double with...

  • In Java: Create an array of Integers with 10 elements, loop (use a for loop) through...

    In Java: Create an array of Integers with 10 elements, loop (use a for loop) through the array of integers printing their values to the screen. Create an array of Strings with 10 elements, loop (use a for loop) through the array of Strings printing their values to the screen. Finally, create an ArrayList of Integers. Use the loop from part 1 above and add each integer as you print it to the ArrayList as well, then start a final...

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