diff --git a/2n+1 problem.java b/2n+1 problem.java deleted file mode 100644 index 7c45ea2..0000000 --- a/2n+1 problem.java +++ /dev/null @@ -1,14 +0,0 @@ -public class Problem2{ - int number = 56; //this is the number given to the program - System.out.println("The inserted number is " + number); //prints the number given to the program - for (i=0; number>1; i++){ //every loop the counter i will be increased by one, that is the total number of operations. continues as long as number is bigger than 1 - if (number%2 != 0){ //if number/2 does not have a remainder then - number=number/2; //the number will be redefined as the number itself divided by 2 - System.out.println("The current number is "+number); //prints the number after dividing it by 2 - } - else { //when the condition of the if statement does not apply (number is not even) then executes this part that - number=number*3+1; //multiplies the number by 3 and adds 1, redefines number to it. - System.out.println("The current number is "+number); - } - System.out.println("The total number of operations was "+i) //prints out the number of operations -} \ No newline at end of file diff --git a/Alex Kerr labs/Alex Kerr Lab 2 guessing game.txt b/Alex Kerr labs/Alex Kerr Lab 2 guessing game.txt new file mode 100644 index 0000000..defa9f8 --- /dev/null +++ b/Alex Kerr labs/Alex Kerr Lab 2 guessing game.txt @@ -0,0 +1,31 @@ +import java.Math + +int num = math.Random(100) + 1; +Print "guess a number between 100 and 1, what is your guess?"; +import user.guess; +int n = 0; +while (num != guess) +{ + if(num > guess) + { + print " your guess is too low, guess again "; + import new user.guess; + n++ + } + else if(num < guess) + { + print " your guess is too high, guess again "; + import new user.guess; + n++ + } + else if(num == guess) + { + Break; + } + +} +if(num == guess) +{ + n++ + Print "you guessed right! it took you " + n + " tries to guess the number correctly"; +} \ No newline at end of file diff --git a/Ben Wortman/BW Lab-2.java b/Ben Wortman/BW Lab-2.java new file mode 100644 index 0000000..9083abf --- /dev/null +++ b/Ben Wortman/BW Lab-2.java @@ -0,0 +1,26 @@ + + + + +public class Problem2{ + + int num = 1579; //starting number + System.out.println("The number is " + num); //says the starting number + + for(i=0; number>1; i++) //add one per loop + + {if (num % 2==0) //if the number is divisible by 2 is a whole number + { num = num/2; //then divide the number by 2 + System.out.println("The current number is " +num);} //prints number after divided by 2 + + else {num = num*3+1; //if not divisible by 2 multiply by 3 and add 1 + + System.out.println("The current number is " +num)}} //prints the number after multiplied by 3 and one added + + System.out.println("There were" +i " operations")} //prints how many times was a number sent through before it was 1 + + + + + + \ No newline at end of file diff --git a/Jack Hinze/Lab 2.txt b/Jack Hinze/Lab 2.txt new file mode 100644 index 0000000..b6685a8 --- /dev/null +++ b/Jack Hinze/Lab 2.txt @@ -0,0 +1,24 @@ +3n+1 Problem +Your program will be given a positive number (less than 10,000). Your program will take the number and follow the appropriate step below: + +when n is even, divide n by 2 +when n is odd, multiply n by 3, and then add 1 +When n is equal to one you stop, otherwise you pick the appropriate step again. + +Please print out the sequence of numbers that lead to 1, starting with n, and how many times (in sumation) the above two commands are run. + +Integer n = input number; +step=0 +While (n > 1){ + if (n%2==0){ + n = n/2; + system.out.print(n); + step +=1 + } + else{ + n = 3*n + 1; + system.out.print(n); + step +=1; + } +} +system.out.print("# of steps:" step) diff --git a/Jackson_Maschman_Question_2 b/Jackson_Maschman_Question_2 new file mode 100644 index 0000000..634aec2 --- /dev/null +++ b/Jackson_Maschman_Question_2 @@ -0,0 +1,25 @@ +public class Lab2 { + public static void main(String[] args) + { + //This is problem #2. + for(int n = 1; n < 10000; n++) //The parameters you set were numbers from 0 to less than 10000, so... here you go. + { + int counter = 0; //This sets the counter to 0 each time it finishes with one of the numbers. + while(n != 1) //This checks the number each loop to see if it has reached 1 yet. + { + if (n % 2 == 0) //This organizes the even numbers into this category. + { + n = (n / 2); + counter = counter + 1; + } + + else { /* This organizes the odd numbers into this category. */ + n = ((n * 3) + 1); + counter = counter + 1; + } + + } + System.out.println(n + " It took " + counter + " loops to complete."); + } + } +} diff --git a/Jared Pohlmann/3n + 1 Problem b/Jared Pohlmann/3n + 1 Problem new file mode 100644 index 0000000..fd73d2e --- /dev/null +++ b/Jared Pohlmann/3n + 1 Problem @@ -0,0 +1,15 @@ +Integer num = input number; +step=0 +While (num > 1){ + if (num%2==0){ + num= num/2; + system.out.print(num); + step += 1; + } + else{ + num = num*3 +1; + system.out.print(num); + step += 1; + } +} +system.out.print("# of steps:" step) diff --git a/Kristen Benes/Lab 2.txt b/Kristen Benes/Lab 2.txt new file mode 100644 index 0000000..d21b226 --- /dev/null +++ b/Kristen Benes/Lab 2.txt @@ -0,0 +1,23 @@ +Lab 2 +Problem 2 +Your program will be given a positive number (less than 10,000). Your program will take the number and follow the appropriate step below: + When n is even, divide n by 2 + when n is odd, multiply n by 3, and then add 1 +When n is equal to one you stop, otherwise you pick the appropriate step again. +Please print out the sequence of number that lead to 1, starting with n, and how many times (in sumation) the above two commands are run. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +n = input number; +step = 0 +While (n > 1){ + If (n%2==0){ + n = (n/2); + system.out.print(n); + step +=1; + } + Else{ + n = n*3+1; + system.out.print(n); + step +=1; + } +} +system.out.print("# of steps:" step) diff --git a/addyvinton/addyvintonlab2.txt b/addyvinton/addyvintonlab2.txt new file mode 100644 index 0000000..653e35e --- /dev/null +++ b/addyvinton/addyvintonlab2.txt @@ -0,0 +1,16 @@ +n = number + +for ( +if(n%2 == 0) +{ + +n = n/2 + +} + +else +{ + +n = (n*3) + 1 + +} \ No newline at end of file diff --git a/bkeller lab2 b/bkeller lab2 new file mode 100644 index 0000000..acebcac --- /dev/null +++ b/bkeller lab2 @@ -0,0 +1,23 @@ +PROBLEM 3 + + + +n = getRandomNumber(0:100); +u = user input; +"guess" = 1 +If (n > u){ + system.out.print(n); + "LOW"; + "guess"+=1; + } +If (n < u){ + system.out.print(n); + "HIGH"; + "guess"+=1; + } +If (n == u) + system.out.print(n); + "CORRECT"; + } +} +system.out.print("number of "guesses:" guesses) diff --git a/piiamt/2n+1 problem.txt b/piiamt/2n+1 problem.txt new file mode 100644 index 0000000..a3b3d0f --- /dev/null +++ b/piiamt/2n+1 problem.txt @@ -0,0 +1,14 @@ +public class Problem2{ + int number = 56; //this is the number given to the program + System.out.println("The inserted number is " + number); //prints the number given to the program + for (i=0; number>1; i++){ //every loop the counter i will be increased by one, that is the total number of operations. continues as long as number is bigger than 1 + if (number%2 != 0){ //if number/2 does not have a remainder (number is divisible by 2) then + number=number/2; //the number will be redefined as the number itself divided by 2 + System.out.println("The current number is "+number); //prints the number after dividing it by 2 + } + else { //when the condition of the if statement does not apply (number is not even) then executes this part that + number=number*3+1; //multiplies the number by 3 and adds 1, redefines number to it. + System.out.println("The current number is "+number); + } + System.out.println("The total number of operations was "+i) //prints out the number of operations +} \ No newline at end of file diff --git a/skylar galloway lab/Lab2 3n+1 problem.txt b/skylar galloway lab/Lab2 3n+1 problem.txt new file mode 100644 index 0000000..fa5348c --- /dev/null +++ b/skylar galloway lab/Lab2 3n+1 problem.txt @@ -0,0 +1,35 @@ +3n+1 + +The 3n + 1 problem +Your program will be given a positive number (less than 10,000). Your program will take the number and follow the appropriate step below: + +when n is even, divide n by 2 +when n is odd, multiply n by 3, and then add 1 +When n is equal to one you stop, otherwise you pick the appropriate step again. + +Please print out the sequence of numbers that lead to 1, starting with n, and how many times (in sumation) the above two commands are run. + +n = input number +int counter=0 /*the value that keeps track of how many times number runs through the loop*/ + +for(int i=0, n!=1 /*(this is tested before loop is executed)*/, i++){ + if (n%2==0){ + w=n/2 //can be n=n/2 + Print w + count= counter +1 + counter=count + n=w + } + else { // (n%2!=0) + x=3*n + y=x+1 + coUnt= counter +1 + counter=coUnt + Print y + n=y + } +} +Print n +Print "The number of times ran throught"+counter + + \ No newline at end of file diff --git a/ylopez20/Lab2.md b/ylopez20/Lab2.md new file mode 100644 index 0000000..20b1ac8 --- /dev/null +++ b/ylopez20/Lab2.md @@ -0,0 +1,17 @@ +//Problem 2 +~~~ +n = input number +for(n=1, n<1000) +{ + n counter = 0; + while(n!=1) + { + if(n%2==0) + ncounter= n+1; + } + + else + n=n*3+1; + ncounter =n+1 + } + ~~~