|
-
February 9th, 2006, 04:37 PM
#1
Junior Member
Need help with sound in java
hey guys, im new here to antionline and i needed some help with one of my programs in Java. im sitting in my computer science class and there are some students that think its funny to playannoying music. my response?
public class h3r3tic
{
public static void main(String args[])
{
int intVal=7;
for(int k=1;k<=5000000;k++)
{
System.out.println((char) + intVal);
k--;
}
}
}
however i was talking to my teacher and she said that in C++ and many other programming languages you can change the pitch and mhz of the constant an ever-so-vengeful beeping. or even add orchange a different sound? any help woudl be great and if you want my personal email for a more personal response its [email protected]
any help you guys can provide would be more than appreciated.
-
February 9th, 2006, 04:53 PM
#2
public class h3r3tic
{
public static void main(String args[])
{
int intVal=7;
for(int k=1;k<=5000000;k++)
{
System.out.println((char) + intVal);
k--;
}
}
}
I dont understand, is there more to this? Seems like System.out.println((char) + intVal); will print some "char" on the screen plus 7, 5,000,000 times. I dont have a compiler on this PC, but I dont see what this will accomplish. Also, why would you want to make the thing make annoying sounds? When I took Java, seems like we made useful programs.
-Deeboe
If you know the enemy and know yourself, you need not fear the result of a hundred battles. If you know yourself but not the enemy, for every victory gained you will also suffer a defeat. If you know neither the enemy nor yourself, you will succumb in every battle.
- Sun Tzu, The Art of War
http://tazforum.**********.com/
-
February 10th, 2006, 07:46 AM
#3
Junior Member
ok, not having a compiler i can understand you not knowing what it does by just looking at it, i wouldnt etiehr probably. that 7 starts out as a 7, not as a character but as an integer. this program converts the integer 7 into its "char" equivalent. so one would naturally think that the "char" equivalent of 7 was a 7, right? wrong! the equivalent is a single beep. putting the conversion in a for statement it does it 5000000 times right? wrong again! if youll look in the brackets of the for statement it has the command 'k--;' which tells java to subtract 1 from integer k (the integer running the for statement) every time it runs through the for statement. so in essence it will sit and beep unendingly.
as to your "why" question. in my post i talked about a rather large group of annoying studnets that like to play annoying music and sounds out of their computers almost constantly in the classroom. this is simply my way of making them stop (it works by the way) im just trying to see if i cant raise or lower the pitch or even get an entirely new sound altogether.
-
February 10th, 2006, 06:24 PM
#4
Originally posted here by janosa
the equivalent is a single beep. putting the conversion in a for statement it does it 5000000 times right? wrong again! if youll look in the brackets of the for statement it has the command 'k--;' which tells java to subtract 1 from integer k (the integer running the for statement) every time it runs through the for statement. so in essence it will sit and beep unendingly.
Ahhh... I see. Seems like a roundabout way of doing it.
You could really cut your code down by doing this:
while(true)
System.out.println((char) + 7);
Of course you need all your brackets and every other call needed to run it, but still.
Anyway, none of that answers your question on changing the pitch. I'm sure there is a way to do it, possibly by creating a .wav file that it calls over and over again. However, the reasoning for doing it just doesn't click with me and I don't really want to work on finding a solution for such a useless cause.
Good luck in your studies!
-Deeboe
If you know the enemy and know yourself, you need not fear the result of a hundred battles. If you know yourself but not the enemy, for every victory gained you will also suffer a defeat. If you know neither the enemy nor yourself, you will succumb in every battle.
- Sun Tzu, The Art of War
http://tazforum.**********.com/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|