| | |
buzz game
![]() |
•
•
Join Date: Dec 2004
Posts: 2
Reputation:
Solved Threads: 0
hi guys, im new here, i have a project that i have to do but cannot complete...
Write a program that prompts the user for a number from 1-9. Then display all of the numbers from 1 to 100 except for any numbers that are evenly divisible by the user’s input or contain the number. For those numbers, print the word “BUZZ.� Notice in the example that every number from 30 to 39 would be “BUZZ� because they all contain the number 3. For extra credit make any number that is both evenly divisible by the users input and also contains the number print “DOUBLE BUZZ.�
Enter a number [1-9]: 3
1 2 DOUBLE BUZZ 4 5 BUZZ 7 8 BUZZ 9 10 11 BUZZ BUZZ 14 BUZZ..
heres what i have so far
so far i can get it to do ne number evenly divisible by the variable, however i do not know how to make it replace a number like 30-39(if 3 is the variable entered)....i tried looking up a way to compare the user input to just 1 character but i couldnt find ne thing relative to my needs....also do not know what to do if its a double buzz situation (both divisible and containing the variable)...id assume that struturally id have to write as
if (divisible or contains variable)
print buzz
else if (divisible and contains)
print double buzz
else
print count
however i just cant for the life of me figure out how to discern if the number contains the variable (if 3 is entered howto make it include 30-39, 73, etc)
Write a program that prompts the user for a number from 1-9. Then display all of the numbers from 1 to 100 except for any numbers that are evenly divisible by the user’s input or contain the number. For those numbers, print the word “BUZZ.� Notice in the example that every number from 30 to 39 would be “BUZZ� because they all contain the number 3. For extra credit make any number that is both evenly divisible by the users input and also contains the number print “DOUBLE BUZZ.�
Enter a number [1-9]: 3
1 2 DOUBLE BUZZ 4 5 BUZZ 7 8 BUZZ 9 10 11 BUZZ BUZZ 14 BUZZ..
heres what i have so far
•
•
•
•
import java.util.Scanner;
public class Buzz
{
public static void main(String[] args)
{
int Num;
Scanner scan = new Scanner(System.in);
do
{
System.out.println("Enter a number from 1-9");
Num = scan.nextInt();
}
while(Num < 1 || Num > 9);
for (int count = 1; count != 101; count++)
{
if (count % Num == 0)
{
System.out.println("BUZZ");
}
else if (
else
{
System.out.println(count);
}
}
}
}
if (divisible or contains variable)
print buzz
else if (divisible and contains)
print double buzz
else
print count
however i just cant for the life of me figure out how to discern if the number contains the variable (if 3 is entered howto make it include 30-39, 73, etc)
•
•
Join Date: Dec 2004
Posts: 2
Reputation:
Solved Threads: 0
well in case ne 1 is wondering i figured out how to fix the program....
i was thinking i had to invoke some method from the math class or something more complicated then what i actually had to do...
since i am only dealing with 2 digit numbers...
say for example i am looking at the number:
35
how do i mathimatically know what the 3 and the 5 seperatly represent
the 3 = 3x10 (remember 10's column and 1's column..etc)
and the 5 = 5x1
so i can seperate the 3 from the 5 using a combination of interger division and modular division
ex: u enter 3 in the program
the program gets to the number 35...both containing and evenly divisible by 3
35 % 3 = 0 then its evenly divisible
35 / 10 = 3 (interger division does not provide remainder) thus forth this number contains a 3
and to check the second digit
35 % 10 = 5....5 is not 3, but if it were this statement would be true
count % Num == 0 (checks even divisibility
count / 10 == Num (checks 10's column to see if it matchs interger entered)
count % 10 == Num (checks 1's column....)
so i got it werking
i was thinking i had to invoke some method from the math class or something more complicated then what i actually had to do...
since i am only dealing with 2 digit numbers...
say for example i am looking at the number:
35
how do i mathimatically know what the 3 and the 5 seperatly represent
the 3 = 3x10 (remember 10's column and 1's column..etc)
and the 5 = 5x1
so i can seperate the 3 from the 5 using a combination of interger division and modular division
ex: u enter 3 in the program
the program gets to the number 35...both containing and evenly divisible by 3
35 % 3 = 0 then its evenly divisible
35 / 10 = 3 (interger division does not provide remainder) thus forth this number contains a 3
and to check the second digit
35 % 10 = 5....5 is not 3, but if it were this statement would be true
count % Num == 0 (checks even divisibility
count / 10 == Num (checks 10's column to see if it matchs interger entered)
count % 10 == Num (checks 1's column....)
so i got it werking
![]() |
Similar Threads
- looking for C++ London 3D Game Porgrammers - Growing proffessional startup company (Software Development Job Offers)
- Roblox seeks Game and Graphics Guru (Software Development Job Offers)
- game programmer needed (Software Development Job Offers)
- Ajax Game Developer Needed for a small project (Web Development Job Offers)
- Matlab code for Fizz Buzz (Computer Science)
- Formatting "Buzz - Fizz" Game, help! (Pascal and Delphi)
Other Threads in the Java Forum
- Previous Thread: How to display a HTML file (in browser window) from Java Program...?
- Next Thread: something is wrong
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing threads tree unlimited utility webservices windows





