. Given a string of at least 3 characters as input, if the length of the string is odd return the character in the middle as a string. If the string is even return the two characters at the midpoint.   public class Class1 {    public static String midString(String str) { //Enter code here } }   -----------   2. Given an array of integers return the sum of the values stored in the first and last index of the array. The array will have at least 2 elements in it

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 12RQ
icon
Related questions
Question

1. Given a string of at least 3 characters as input, if the length of the string is odd return the character in the middle as a string. If the string is even return the two characters at the midpoint.

 

public class Class1 {

  

public static String midString(String str) {

//Enter code here

}

}

 

-----------

 

2. Given an array of integers return the sum of the values stored in the first and last index of the array. The array will have at least 2 elements in it

 

public class Class1 {

  

public static int endSum(int[] values) {

//Enter code here

}

  

}

 

-----------

 

3. The method takes a string as a parameter. The method prints treat if the string is candy or chocolate (of any case, such as CaNdY) Otherwise print trick

 

import java.util.Scanner;

 

public class Class1 {

public static void trickOrTreat(String str) {

//Enter code here

}

  

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

trickOrTreat(s.nextLine());

}

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Program on Numbers
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,