Use a for loop to print all characters at odd index * positions of a string, one per line. * You should use str.length() as the length of the string, since * Codecheck will use another string to test your program. * Step 1: Enter your name for @author and today's date for @version * @author * @version */ public class 0ddIndexChars { public static void main(String(] args) { String str = "Introduction to Programming"; // Step 2: Use a for loop to print all chars at the odd // index positions, one per line for (int i=0;i

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Fix the code
* Use a for loop to print all characters at odd index
31
2.
* positions of a string, one per line.
* You should use str.length() as the length of the string, since
* Codecheck will use another string to test your program.
4
* Step 1: Enter your name for @author and today's date for @version
* @author
* @version
7
8.
9.
10
*/
public class OddIndexChars
{
public static void main(String[] args)
{
String str = "Introduction to Programming";
11
12
13
14
15
16
// Step 2: Use a for loop to print all chars at the odd
//
17
18
index positions, one per line
19
for(int i=0;i<str.length();i++)
{
if(i%2!=0)
20
21
22
23
System.out.println(i+" "+str.charAt (i));
}
24
25
26
27
28
29
30
31
}
32
33
CodeCheck
Reset
Download
Running program with substitutions
Transcribed Image Text:* Use a for loop to print all characters at odd index 31 2. * positions of a string, one per line. * You should use str.length() as the length of the string, since * Codecheck will use another string to test your program. 4 * Step 1: Enter your name for @author and today's date for @version * @author * @version 7 8. 9. 10 */ public class OddIndexChars { public static void main(String[] args) { String str = "Introduction to Programming"; 11 12 13 14 15 16 // Step 2: Use a for loop to print all chars at the odd // 17 18 index positions, one per line 19 for(int i=0;i<str.length();i++) { if(i%2!=0) 20 21 22 23 System.out.println(i+" "+str.charAt (i)); } 24 25 26 27 28 29 30 31 } 32 33 CodeCheck Reset Download Running program with substitutions
str
Actual Expected
1 n
in
3 r
5 d
7 с с
i
9 i
11 n
n
fail "Introduction to Programming" 13 t
15
17 r
19 g
21 a
a
23 m
m
25 n
1 a
a
3 а
a
5 P
7 o
9 r
11 m
fail "Java Programming"
r
13 i
15 g
i
Score
0/3
Transcribed Image Text:str Actual Expected 1 n in 3 r 5 d 7 с с i 9 i 11 n n fail "Introduction to Programming" 13 t 15 17 r 19 g 21 a a 23 m m 25 n 1 a a 3 а a 5 P 7 o 9 r 11 m fail "Java Programming" r 13 i 15 g i Score 0/3
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Basics of loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education