Advertisement
Guest User

question3

a guest
Apr 4th, 2020
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 KB | None | 0 0
  1. /*------------------------------------------------------
  2. My name: Maysar Mahawi
  3. My subject code: DPIT 111
  4. My student number: 6548684
  5. My email address: msmm828@uowmail.edu.au
  6. Assignment number: 01
  7. -------------------------------------------------------*/
  8.  
  9.  
  10. package Question3;
  11.  
  12. import java.util.Scanner;  // Import the Scanner class
  13.  
  14. public class Question3 {    // a class called Question3
  15.  
  16.    
  17.      public static String stringMerge (String a, String b, int c ) {      // we creating a method called stringMerge with two strings and one int
  18.          
  19.          
  20.          String input1 = a.substring (0, c);    // we created a new variable with a indentifier to store the new data, 0 being the start and c being the end of the String A.
  21.          
  22.          String input2 = b.substring(c);   // created a new variable with a indentifier to store the new data, c being the start of String b with no end as to how many letters it can pick up.
  23.          
  24.          return input1 + input2; // takes input1 and input2 and store them into the method "stringMerge"
  25.                  
  26.          
  27.      }
  28.      
  29.      
  30.    
  31.     public static void main(String[] args) {     // the main() method
  32.        
  33.  
  34.         Scanner inputs = new Scanner (System.in);  // scanner creates scanner object
  35.        
  36. // input 1  (String)
  37.         System.out.print("Enter the first string: ");
  38.         String string1 = inputs.nextLine(); // read the user input
  39.        
  40. // input 2 (String)
  41.         System.out.print ("Enter the second string: ");
  42.         String string2 = inputs.nextLine(); // read the user input
  43.        
  44. // input 3 (int)
  45.         System.out.print ("Enter an index: ");
  46.         int index = inputs.nextInt (); // Read user input
  47.        
  48.  stringMerge(string1, string2, index); // we are calling the stringMerge method
  49.                
  50.   System.out.println ("The merged string of " + string1 + " and " + string2 + " is " + stringMerge(string1, string2, index));
  51.        
  52.     }
  53.    
  54.  
  55.     }
  56.  
  57. // Extra information: My comments are not as detailed since that all comments would be very similar to question 1 and 2.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement