Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Magic number Java Program

Have Programming Question? Ask it here!
 
 
 


Tyler Essinger
Magic number Java Program
0 Answer(s)      2 years and 6 months ago
Posted in : Java Beginners


write a program that guesses what number the user is thinking of. Below is a sample transcript: Think of a number between 1 and 255. I will guess the number you are thinking of. 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 Is it in the list above? (yes or no): yes

2 3 6 7 10 11 14 15 18 19 22 23 26 27 30 31 34 35 38 39 42 43 46 47 50 51 54 55 58 59 62 63 66 67 70 71 74 75 78 79 82 83 86 87 90 91 94 95 98 99 102 103 106 107 110 111 114 115 118 119 122 123 126 127 130 131 134 135 138 139 142 143 146 147 150 151 154 155 158 159 162 163 166 167 170 171 174 175 178 179 182 183 186 187 190 191 194 195 198 199 202 203 206 207 210 211 214 215 218 219 222 223 226 227 230 231 234 235 238 239 242 243 246 247 250 251 254 255 Is it in the list above? (yes or no): no

4 5 6 7 12 13 14 15 20 21 22 23 28 29 30 31 36 37 38 39 44 45 46 47 52 53 54 55 60 61 62 63 68 69 70 71 76 77 78 79 84 85 86 87 92 93 94 95 100 101 102 103 108 109 110 111 116 117 118 119 124 125 126 127 132 133 134 135 140 141 142 143 148 149 150 151 156 157 158 159 164 165 166 167 172 173 174 175 180 181 182 183 188 189 190 191 196 197 198 199 204 205 206 207 212 213 214 215 220 221 222 223 228 229 230 231 236 237 238 239 244 245 246 247 252 253 254 255 Is it in the list above? (yes or no): yes

8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31 40 41 42 43 44 45 46 47 56 57 58 59 60 61 62 63 72 73 74 75 76 77 78 79 88 89 90 91 92 93 94 95 104 105 106 107 108 109 110 111 120 121 122 123 124 125 126 127 136 137 138 139 140 141 142 143 152 153 154 155 156 157 158 159 168 169 170 171 172 173 174 175 184 185 186 187 188 189 190 191 200 201 202 203 204 205 206 207 216 217 218 219 220 221 222 223 232 233 234 235 236 237 238 239 248 249 250 251 252 253 254 255 Is it in the list above? (yes or no): yes

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 Is it in the list above? (yes or no): no

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 Is it in the list above? (yes or no): no

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 Is it in the list above? (yes or no): yes

128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 Is it in the list above? (yes or no): no

You are thinking of 77

The program prints out 8 sets of numbers. Notice the pattern: 1.starting at 1 print the number, skip the next one, print the next one, skip the next one, etc. 2.starting at 2 print the next 2 numbers, skip the next 2, print the next 2, skip the next 2, etc. 3.starting at 4 print the next 4 numbers, skip the next 4, print the next 4, skip the next 4, etc. 4.starting at 8 print the next 8 numbers, skip the next 8, print the next 8, skip the next 8, etc. 5.etc

You will implement this using nested for loops to print out the 8 sets of numbers (that is, you cannot just cut-n-paste these numbers into your program).

You can then calculate the number the person is thinking of by simply adding up the first number in each one of the lists the user said "yes" to. In the example above this would be 1+4+8+64 = 77.


Advertisement
View Answers

Related Tutorials/Questions & Answers:
Magic number Java Program
Magic number Java Program  write a program that guesses what number the user is thinking of. Below is a sample transcript: Think of a number between 1 and 255. I will guess the number you are thinking of. 1 3 5 7 9 11 13 15 17
Magic number in java
Magic number in java  Hi.. Can any one tel how to watch a magic number of a program?   import java.util.*; class MagicNumber...==1) System.out.print("Magic Number"); else
Advertisements
Magic Squares - Java Beginners
Magic Squares  Magic Squares A magic square is an n by n grid... on this definition, an example magic square for n = 4 is 16 15 1 2 6 4 10 14 9 8 12 5 3... than n2). boolean checkmagic() Returns true if the matrix is a magic square
program on factorial of a given number in java
program on factorial of a given number in java  please tell me, how to write program on factorial of a given number in java
program on factorial of a given number in java
program on factorial of a given number in java  please tell me, how to write program on factorial of a given number in java
Robust Magic Square Tester - Java Beginners
Robust Magic Square Tester  I need a program to determine if a file of numbers is a magic-square. a magic square of order n is an arrangement of n... diagonals sum to the same constant. A normal magic square contains the integers
Prime Number program in Java
Prime Number program in Java will print the prime numbers between 1 to any given number. Prime Number is a number that is not divisible by any number other... program in Java: package Tutorial; public class PrimeNumber { public static
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers
Java Automorphic number program - Java Beginners
Java Automorphic number program  Write a program to read a positive... void main(String args[]){ System.out.print("Enter any number...){ if ((n*n) % d == n){ System.out.println("Automorphic Number
Prime number program in java
Prime number program in java In this example you will learn how to write a program to generate and check  prime number  in java. As we know prime number are those number which are divisible by 1 or itself, first define
JAVA program - Java Beginners
JAVA program  Write a JAVA program to accept a number and find whether it is a magic number
JAVA program - Java Beginners
JAVA program  Write a JAVA program to accept a number and find whether it is a magic number
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file
Check Perfect Number in Java Program
How to Check Perfect Number in Java Program A perfect number is a positive... to the number itself. For example 6 is a perfect number as 1,2 and3 are its divisors and the sum of divisors=1+2+3=6. Here we have created a program that will take
ID number program
ID number program  hi can anyone help me with the following program. a program that can determine a person,s date of birth, age, gender and citizenship by just entering the id number. thanks in advance
How to Check Automorphic Number using Java Program
How to Check Automorphic Number using Java Program Automorphic numbers are the numbers whose square ends with the number itself or you can say it is a number whose square ends with the given integer. For example,5 is an automorphic number
write a java program to print marklist of "n " students. input Register number, name and marks of three subjects.
write a java program to print marklist of "n " students. input Register number, name and marks of three subjects.  write a java program to print marklist of "n " students. input Register number, name and marks of three subjects
write a program in java Adding up the subscript(st,nd,rd,th) to the number of days in a input string
write a program in java Adding up the subscript(st,nd,rd,th) to the number of days in a input string    write a program in java Adding up the subscript(st,nd,rd,th) to the number of days in a input string ex:If a user enters
The Array Palindrome Number in Java
The Array Palindrome Number in Java       This is a Java simple palindrome number program... program. The array palindrome number arrange the array number. This session
Prime Number in Java
Prime Number in Java In this Java tutorial , you will learn how to write a Java program to get prime numbers between 1 to the desired number. To start... prime number. ADS4ThUnitADS Here is the code of the java Program to get prime
number of stairs - Java Beginners
number of stairs  1. Write a program that prints an n-level stair case made of text. The user should choose the text character and the number...(); } } } ----------------------------------- read for more information, http://www.roseindia.net/java/master
PHP Magic Constant
PHP Magic Constants: In PHP there are various predefined constants, but many... of the magic constants are as follows: 1) __LINE__: This constant is used to indicate the current line number of the file. 2) __DIR__ :  This constant is used
getting random number in java
getting random number in java  getting random number in java Hi... and scaling the random number in my Java Random number eample. but for some reason... to generate the random number in Java Thanks in Advance
Number Convert - Java Beginners
passString(int number){ int num, q ; if (number < 10 ){ displayOutput(a[number...]) ; } if ( number > 19 ){ num = number % 10 ; if ( num == 0 ){ q = number / 10 ; displayOutput (d[q-2]) ; } else{ q = number / 10 ; displayOutput(a[num
PHP Magic Methods
Magic Methods in PHP: In PHP there are so many methods are included in recent versions, magic methods are one of them. The magic methods are listed below..._state() __clone() In the above list of the magic methods it is very
prime number - Java Beginners
prime number  i want to write a code in java that picks prime numbers... boolean isPrime(int number){ boolean isPrime=false; int i=(int) Math.ceil(Math.sqrt(number)); while (i>1
number - Java Interview Questions
number  apka number kya hai aap apna number mera id per send ker do
prime number - Java Beginners
prime number  this project is to determine if a phone number is a prime number. if the number is a prime number then print a message to the effect. if the number is not a prime number then print the prime factors of the number
Collection of Large Number of Java Sample Programs and Tutorials
Collection of Large Number of Java Sample Programs and Tutorials Java... example of java program is provided that shows you how you can...; HelloWorld Java Program Simple
add number - Java Beginners
add number  Q. write a programe to add three number. The number input... input=new Scanner(System.in); System.out.println("Enter first number"); int a=input.nextInt(); System.out.println("Enter second number"); int b
java program
java program  Write a java program to find the number of Positive numbers in m* n matrix
perfect number - Java Beginners
perfect number  An integer number is said to be a perfect number.... For example, 6 is a perfect number because 6 = 1+2+3. Write a method perfect that determines if parameter number is a perfect number. Use this method
A program to find the sum of odd number
A program to find the sum of odd number In this section you will learn how to find the sum of odd number in the series up to the given number in java... number. import java.util.Scanner; public class Sum { public static
a Java program
a Java program    Write a Java program to print even numbers from 2 to 1024? Write a Java program to print ? My Name is Mirza? 100 times? Write a Java program to print Fibonacci Series? Write a Java program to reverse a number
String program - Java Beginners
String program  write a program to accept a word. Pass it to the function magic(String x). The function checks the string for the presence... prints it is a magic string otherwise it prints not a magic string.  
GUESS NUMBER - Java Beginners
GUESS NUMBER  Create a guessing game that picks a random number...() { super("Guess Number"); randomNumber = new Random().nextInt(100) + 1...); panelBottom.add(comment, BorderLayout.SOUTH); panel.add(new JLabel(" Guess a number from
Convert Number to Roman Number Using Java
Java Convert Number to Roman Numerals In this section, you will learn how to convert the number to roman number.  To do this, we have created a class... and the method convertIntegerToRoman(int n) convert the specified number into roman
java program
java program  write a program to read 10 numbers from user and store it in a array. display the maximum n minimum number in the array
Java program
Java program  Write a program which performs to raise a number to a power and returns the value. Provide a behavior to the program so as to accept any type of numeric values and returns the results
java program
java program  . Write a program which performs to raise a number to a power and returns the value. Provide a behavior to the program so as to accept any type of numeric values and returns the results
Java reverse number
Java reverse number In this tutorial, you will learn how to reverse a number in java. In java, you can use arithmetic operators like division operator(/) and remainder operator(%) to reverse the number. The division operator returns
Write a program to calculate factorial of any given number
program to calculate factorial of any given number. First of all define a class... in java. Here is the code of program: import ... Factorial Examples - Java Factorial Example to calculate factorial of any
Java Program - Java Beginners
Java Program  Write a java program to find out the sum of n-number of digits of a given number by the user
Advertisements
 

 

 

DMCA.com