(Java) Complete the method definition to output the hours given minutes.

(Java) Complete the method definition to output the hours given minutes. Output for sample program: 3.5

  1. secretID.concat(spaceChar);
  2. secretID.concat(lastName);
  3. import java.util.Scanner;
  4. public class CombiningStrings {
  5. public static void main (String [] args) {
  6. String secretID = "Barry";
  7. String lastName = "Allen";
  8. char spaceChar = ' ';
  9. /* Your solution goes here */
  10. System.out.println(secretID);
  11. return;
  12. }
  13. }

Answer

  1. /***************************************************
  2. * This program is used to Concatenate the strings *
  3. **************************************************/
  4. // import statement
  5. import java.lang.*;
  6. // Create a class CombiningStrings
  7. public class CombiningStrings
  8. {
  9. // Create a main method
  10. public static void main(String[] args)
  11. {
  12. String secretID = "Barry";
  13. String lastName = "Allen";
  14. char spaceChar = ' ';
  15. /* Your solution goes here */
  16. // Convert character data type to string data type
  17. // The concatenation operation occurs with two string data
  18. //types
  19. String strSpaceChar = Character.toString(spaceChar);
  20. // Concatenate two strings secretID and strSpaceChar
  21. secretID = secretID.concat(strSpaceChar);
  22. // Concatenate two strings secretID and lastName
  23. secretID = secretID.concat(lastName);
  24. // Display secretID
  25. System.out.println(secretID);
  26. return;
  27. }
  28. }

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts