Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package principal;
- import java.util.Scanner;
- public class Main{
- public static void main(String[] args) {
- Scanner sca = new Scanner(System.in);
- int min,max,teste;
- int cycle = 0;
- int cont;
- System.out.println("Insira um numero x");
- min = sca.nextInt();
- System.out.println("Entre com o valor de j");
- max = sca.nextInt();
- for(int y = min ; y <= max; y++) {
- cont = 1; // começa em um por que nao conta o 1
- teste = y;
- while(teste > 1) {
- if(teste%2 == 1){
- teste = (3*teste)+1;
- cont++;
- }else {
- teste = teste/2;
- cont++;
- }
- }
- if(cont > cycle) {
- cycle = cont;
- }
- }
- System.out.println(min+" "+" "+ max +" "+cycle);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement