Skip to content

Instantly share code, notes, and snippets.

@gmfc
Created August 23, 2013 11:41
Show Gist options
  • Select an option

  • Save gmfc/6318417 to your computer and use it in GitHub Desktop.

Select an option

Save gmfc/6318417 to your computer and use it in GitHub Desktop.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package palindromos;
/**
*
* @author 31371477
*/
public class Palindromos {
//1º método:
public static boolean metodo1(String in){
//String out = "";
boolean result = false;
int i = (in.length()-1);
int j = 0;
for(;i!=j||i==(j-1);i--,j++){
if(in.charAt(i)==in.charAt(j)){
result = true;
}else{
return false;
}
}
return result;
}//metodo1
public static boolean metodo2(String in){
String comp = "";
for(int i=in.length();i>0;i--){
comp = comp + in.charAt(i-1);
}
if(comp.equals(in)){
return true;
}else{
return false;
}
}//metodo2
public static String noSpace(String in){
return in.replace(" ", "");
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package palindromos;
import org.junit.Assert;
import org.junit.Test;
/**
*
* @author 31371477
*/
public class PalindromosTest {
public PalindromosTest() {
}
/**
* Test of main method, of class Palindromos.
*/
@Test
public void testMain() {
}
/**
* Test of metodo1 method, of class Palindromos.
*/
@Test
public void testMetodo1() {
String s = "arara";
Assert.assertTrue(Palindromos.metodo1(s));
}
/**
* Test of metodo2 method, of class Palindromos.
*/
@Test
public void testMetodo2() {
String s = "arara";
Assert.assertTrue(Palindromos.metodo2(s));
}
/**
* Test of noSpace method, of class Palindromos.
*/
@Test
public void testNoSpace() {
String t = "subi no onibus";
Assert.assertEquals(Palindromos.noSpace(t), "subinoonibus");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment