YoSoy196
package poo; | |
//Gilberto Rogel García WSQ08 YoSoy196 | |
import javax.swing.*; | |
public class YoSoy196 { | |
int low, | |
up, | |
pal=0, | |
non=0, | |
lych=0; | |
public YoSoy196(int x, int y){ | |
this.low=x; | |
this.up=y; | |
} | |
void lol(){ | |
String palin=""; | |
String palinInverse=""; | |
long p1, | |
p2, | |
suma, | |
j; | |
for(int i=low; i<=up; i++){ | |
palin= ""+i; | |
//System.out.println("Palin: "+palin); | |
palinInverse= new StringBuilder(palin).reverse().toString(); //Esto hace que a palinInverse se le asigne el valor de palin pero al revez para despues compararlos y checar si son palindromos | |
//System.out.println("Palin Inverse: "+palinInverse); | |
if(palin.equals(palinInverse)){ // | |
pal++; | |
continue; | |
} | |
for(j=0; j<30; j++){ | |
p1=Long.parseLong(palin); | |
p2=Long.parseLong(palinInverse); | |
suma=p1+p2; | |
palin="" +suma; | |
palinInverse= new StringBuilder(palin).reverse().toString(); | |
if(palin.equals(palinInverse)){ | |
non++; | |
break; | |
} | |
} | |
if(j==30){ | |
System.out.println("Lychrel candidate found: "+i); | |
lych++; | |
} | |
} | |
System.out.println("Range of numbers from "+ low + " to "+up); | |
System.out.println("Natural palindromes: "+ pal); | |
System.out.println("non-Lycherels encountered: "+ non); | |
System.out.println("Lycherel number candidates: "+ lych); | |
} | |
public static void main(String[] args){ | |
int low= Integer.parseInt(JOptionPane.showInputDialog("Give me the lower bound")), | |
up= Integer.parseInt(JOptionPane.showInputDialog("Give me the upper bound")); | |
YoSoy196 banana= new YoSoy196(low,up); | |
banana.lol(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment