Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*------------------------------------------------------
- My name: Maysar Mahawi
- My subject code: DPIT 111
- My student number: 6548684
- My email address: msmm828@uowmail.edu.au
- Assignment number: 01
- -------------------------------------------------------*/
- package Question3;
- import java.util.Scanner; // Import the Scanner class
- public class Question3 { // a class called Question3
- public static String stringMerge (String a, String b, int c ) { // we creating a method called stringMerge with two strings and one int
- 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.
- 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.
- return input1 + input2; // takes input1 and input2 and store them into the method "stringMerge"
- }
- public static void main(String[] args) { // the main() method
- Scanner inputs = new Scanner (System.in); // scanner creates scanner object
- // input 1 (String)
- System.out.print("Enter the first string: ");
- String string1 = inputs.nextLine(); // read the user input
- // input 2 (String)
- System.out.print ("Enter the second string: ");
- String string2 = inputs.nextLine(); // read the user input
- // input 3 (int)
- System.out.print ("Enter an index: ");
- int index = inputs.nextInt (); // Read user input
- stringMerge(string1, string2, index); // we are calling the stringMerge method
- System.out.println ("The merged string of " + string1 + " and " + string2 + " is " + stringMerge(string1, string2, index));
- }
- }
- // 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