Question

1.Write exactly one for loop statement that prints this column of nine words: snake frog snake...

1.Write exactly one for loop statement that prints this column of nine words:

snake
frog
snake
frog
snake
frog
snake
frog
snake

Enter your loop statement in the box below.
Question 2. 5 points

Suppose s is any String. Write a loop that prints s backwards, and with the symbol - (dash), printed twice, between pairs of characters and also at the very end:

If s is "horse", your loop should print e--s--r--o--h--

If s is "pig", your loop should print g--i--p--

if s is "Hi Jo!", you're loop should print !--o--J-- --i--H--

Enter your looping code in the box below.

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


1)

for(int i=0;i<9;i++)

{

if(i%2==0)

System.out.println("snake");

else

System.out.println("frog");

}

2)

for(int i=s.length()-1;i>=0;i--)

{

System.out.print(s.charAt(i)+"--");

}

System.out.println("");


Add a comment
Know the answer?
Add Answer to:
1.Write exactly one for loop statement that prints this column of nine words: snake frog snake...
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
  • 1.The code box below includes a live 2 dimensional array variable called gridNums. This array holds...

    1.The code box below includes a live 2 dimensional array variable called gridNums. This array holds integers. You cannot see its declaration or initialization. What value is in the zeroth (initial) position of the second row? Print this array entry to the console. (Note: remember that the second row is actually row 1). Enter your code in the box below. 2.The code box below includes a live 3x3 2-dimensional array variable called fredsNums. This array holds integers. You cannot see...

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • in c++ language 1.Re-write the following for loop statement by using a while loop statement: int...

    in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){                 sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() {    int score, highest;             //missing portion of the program             return 0;    } 1(c). Find the missing portion of the following code, so the...

  • Write a program that defines a Print Job structure as follows: 1) An integer job Id...

    Write a program that defines a Print Job structure as follows: 1) An integer job Id 2) A string user name (maximum 25 characters) 3) An integer tray (tray will hold the tray number 1 for 8 1/2 by 11 paper, number 2 for 8 1/2 by 11 paper, and number 3 for 8 1/2 by 14 paper) 4) An integer for paper size (this will hold a percentage: 100% is normal, 150% is 1.5 times the size) 5) A...

  • (Write or type in answers, except for problem #15, which should be entered as a small...

    (Write or type in answers, except for problem #15, which should be entered as a small program, tested, and submitted in Repl.it) 1. Write a Python statement to define a list named temps using the following elements, in order: 95, 100, 77, 54, 103, 82 2. a) What is the length of the list temps? b) What Python function can be used to obtain the length of the list? Use it in a statement to obtain the length of temps...

  • Download the file patternMatch.c from the course website. This file contains part of a program to...

    Download the file patternMatch.c from the course website. This file contains part of a program to do pattern matching. The function main looks like this: int main() { char text (40), pattern (40), *position; int textlength, patternlength; printf ("Enter text: "); textlength = readline (text, 40); printf ("Enter pattern: "); patternlength = readline (pattern, 40); position = findmatch (pattern, text, patternlength, textlength); printmessage (position, text, patternlength, textlength); The function readline should read a line of characters from the keyboard. The...

  • CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods...

    CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods Create a folder called Unit03 and put all your source files in this folder. Write a program named Unit03Prog1.java. This program will contain a main() method and a method called printChars() that has the following header: public static void printChars(char c1, char c2) The printChars() method will print out on the console all the characters between c1 and c2 inclusive. It will print 10...

  • I need help with a C++ assignment: Write a program containing the following: 1. Variable Definitions...

    I need help with a C++ assignment: Write a program containing the following: 1. Variable Definitions only as (DieRoll, Guess, cnt1, cnt2) followed by this statement: srand((unsigned int)time (NULL)); which will give the random number generator a random starting point. Note: srand and rand require the TIME.H (or iomanip) cnt1 and cnt2 will be used in Chapter 5 drop box as counters for loops. Do NOT create additional variables. Points will be taken off for any additional variable creation. 2....

  • Write a program named text_indexing.c that does the following: Reads text and stores it as one...

    Write a program named text_indexing.c that does the following: Reads text and stores it as one string called text. You can read from a file or from the user. (In my implementation, I read only one paragraph (up to new line) from the user. With this same code, I am able to read data from a file by using input redirection (executable < filename) when I run the program. See sample runs below). You can assume that the text will...

  • PA #1: Word Counter Tabulating basic document statistics is an interesting exercise that leverages your knowledge...

    PA #1: Word Counter Tabulating basic document statistics is an interesting exercise that leverages your knowledge of strings, files, loops, and arrays. In this homework, you must write a C++ program that asks the user for an input and output file. For each line in the input file, write a modified line containing a line number to the output file. Additionally, calculate the number of paragraphs, lines, words, and characters. Write the summary information to the bottom of the output...

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