Answered step by step
Verified Expert Solution
Question
1 Approved Answer
If aLine has an odd number of characters, print The line has an odd number of characters. Otherwise, print the two middle characters of aLine
If aLine has an odd number of characters, print "The line has an odd number of characters." Otherwise, print the two middle characters of aLine. when I plug in " This line starts with a blank" I get ts but the key says rt. (num is defined as the length of the string) int middle1 = num / 2; int middle2 = (num / 2)-1; char atMiddle1 = temp.charAt(middle1); char atMiddle2 = temp.charAt(middle2); if (num % 2 != 0) { System.out.println("The line has an odd number of characters."); } else System.out.println("The two middle characters are " + atMiddle1+atMiddle2);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started