Structure of the Problem Requirements
In this problem we will learn how to make a sound in Java program. Before this tutorial we upload program how to make sound in C++. In both case Beep function is used. In Java Beep exist in java.awt.Toolkit class. In this problem we used for loop and used a thread which play the sound continuously. Through Beep function beginners student can easily make a small security system which help them to understand it more clearly. Here is the source code of this problem which help you in better understanding.
Source Code
package soundinjava;
import java.awt.Toolkit;
import java.util.Scanner;
public class sound {
public static void main (String args [])
{
int a;
Scanner input = new Scanner (System.in);
System.out.println(" \t \t \t LEP TUTORIALS \n");
System.out.println(" Do You Want to Play Sound? \n");
System.out.println(" 1. Start \n");
a = input.nextInt();
if (a ==1)
{
for(int i = 0 ; i < 100; i++){
Toolkit.getDefaultToolkit().beep();
try{
Thread.sleep(100);
}
catch(Exception e)
{
System.out.print("Sorry Sound Can't Play ! \n \n ");
}
}
}
}
}
Output of the program
![]() |
| Beep function in Java |

