Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //3
- public static void writeSequence(int n){//10-5 9-4 8-3 7-2
- if(n<1){
- throw new IllegalArgumentException("Value cannot be less than 1!");
- }
- if(n==1){
- System.out.print("1 ");
- }
- else if(n==2){
- System.out.print("1 1");
- }
- else {
- int r = n - n / 2;
- System.out.print(r +" ");
- writeSequence(n-2);
- System.out.print(r + " ");
- }
- }
- //7
- public static void writeChars(int n){
- if(n<1){
- throw new IllegalArgumentException("Value cannot be less than 1!");
- }
- if(n==1){
- System.out.print("*");
- }
- else if(n==2){
- System.out.print("**");
- }
- else{
- System.out.print("<");
- writeChars(n-2);
- System.out.print(">");
- }
- }
- //isPalindrome
- public static boolean isPalindrome(String s){
- if(s.length()<=1){
- return true;
- }
- if(s.charAt(0)==s.charAt(s.length()-1)){
- return (isPalindrome(s.substring(1,s.length()-1)));
- }
- else {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment