Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package project;
- import java.util.Scanner;
- public class newassignment7 {
- public static String duplicate(String input1) {
- int dup = 0;
- if(input1.length()%2 == 0) { //Checks if length is even
- dup = (input1.length()*input1.length())*2; //then multiply by itself and * 2
- }
- else { //If odd
- dup = input1.length()*input1.length(); //multiply * itself
- }
- int c = 0;
- char[] newc = new char[dup]; //create new array of chars
- for(int i = 0; i < input1.length();i++) { //for loop runs # of times as the input
- for(int j = 0; j < (dup/input1.length());j++){ //2nd loop runs how many time each char repeats
- newc[c] = input1.charAt(i);
- c++; //char at value
- }
- }
- System.out.print("The duplicated String is: ");
- for(int i = 0; i < newc.length;i++) {
- System.out.print(newc[i]);
- }
- return input1;
- }
- public static String isEdhesivePalindrome(String input2) {
- int flag = 0;
- if(input2.length() <3 || input2.length()>15) { //Checks for length
- flag = 1;
- //break;
- }
- char[] newc = new char[input2.length()]; //Creates array of chars
- int c = 0;
- for(int i = 0; i < newc.length;i++) {
- newc[i] = input2.charAt(c);
- c++;
- }
- for(int i = 0; i < newc.length;i++) { //Changes all possible inputs
- if(newc[i] == '4') {
- newc[i] = 'a';
- }
- if(newc[i] == '3') {
- newc[i] = 'e';
- }
- if(newc[i] == '0') {
- newc[i] = 'o';
- }
- }
- String b = new String(newc); //creates new string
- System.out.println('\n'+ "string: " + b + '\n');
- int half = b.length()/2; //calculate half of the string
- for(int i = 0; i < half; i++) { //first half comparison
- for(int j = b.length()-1; j > half; j--) { //second half comparison
- System.out.println(newc[i] + "compared to: " + newc[j] ); //debugging
- if(newc[i] != newc[j]) { //if theyre not equal flag
- flag = 1 ;
- break;
- }
- i++;
- }
- }
- if(flag == 1 ) {
- System.out.println("Too bad, that isn't an Edhesive Palindrome.");
- }
- if(flag == 0) {
- System.out.println("Nice, you found an Edhesive Palindrome!");
- }
- return input2;
- }
- public static Double numberScramble(Double input3) {
- Double num = input3;
- double end = 0;
- if(num < 0) {
- end = 0.0;
- System.out.println("The scrambled number is: " + end);
- }
- else {
- num = num + 5;
- num = num /2;
- num = Math.sqrt(num);
- System.out.println("The scrambled number is: " + num);
- }
- return input3;
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Welcome to the Methods Sampler Platter. Please enter a String to duplicate.");
- String input1 = scanner.nextLine();
- duplicate(input1);
- System.out.println('\n' + "Next, please enter a String to check for Edhesive Palindromes.");
- String input2 = scanner.nextLine().toLowerCase();
- isEdhesivePalindrome(input2);
- System.out.println("Almost done! Please enter a number to scramble.");
- double input3 = scanner.nextDouble();
- numberScramble(input3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement