Created
April 20, 2019 09:51
-
-
Save SibghatullahDurrani/dccf666ecfc6af1b9324868c54e091d4 to your computer and use it in GitHub Desktop.
Solution to weekly questions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Question1 { | |
| public static void main(String[] args) { | |
| //Outputs for BunnyEar Functions | |
| System.out.println(bunnyEars(0)); | |
| System.out.println(bunnyEars(1)); | |
| System.out.println(bunnyEars(2)); | |
| System.out.println(bunnyEars(234)); | |
| //Output for Equals Not Function | |
| System.out.println(equalsNot("This is not")); | |
| System.out.println(equalsNot("This is notnot")); | |
| System.out.println(equalsNot("noisxxnotyynotxisi")); | |
| } | |
| public static int bunnyEars (int num) | |
| { | |
| //Adds the number into itself and return it | |
| return num+num; | |
| } | |
| public static boolean equalsNot(String words) | |
| { | |
| int Is = 0; | |
| int Not = 0; | |
| String wordsCopy; | |
| //Making a copy of the string | |
| wordsCopy=words; | |
| //The loop will run until there are no "is" left in the string | |
| while(wordsCopy.indexOf("is")!=-1) | |
| { | |
| //iterating the counts of IS | |
| Is++; | |
| //Reinitializing the copy of the string from is till the end of the string | |
| wordsCopy = wordsCopy.substring(wordsCopy.indexOf("is")+2,wordsCopy.length()); | |
| } | |
| //Making a copy of the string again to count not | |
| wordsCopy=words; | |
| //The loop will run until there are no "not" left in the string | |
| while(wordsCopy.indexOf("not")!=-1) | |
| { | |
| //iterating the counts of IS | |
| Not++; | |
| //Reinitializing the copy of the string from is till the end of the string | |
| wordsCopy = wordsCopy.substring(wordsCopy.indexOf("not")+3,wordsCopy.length()); | |
| } | |
| //returning true or false accordingly | |
| return Is==Not; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment