Пример проигрывания звука в android
void soundTime(int t){
toast("СИГНАЛ ЧЕРЕЗ "+t/60+" МИН.");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mp= MediaPlayer.create(Sirena.this,R.raw.alarm);
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
mediaPlayer.release();
}
});
mp.setLooping(true);
mp.start();
b.setEnabled(true);
b.setText("ПОДЪЁМ!!!");
}
},1000*t);
}
Путь до директории с исполняемым файлом
Код определяет путь до директории где находиться исполняемый архив(jar) с программой. Может понадобиться при необходимости создания/удаления или(и) записи/чтения файлов из этой директории.
import java.io.File;
public class TestClass {
public static void main(String[] args) {
String myJarPath = TestClass.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String dirPath = new File(myJarPath).getParent();
System.out.println(dirPath);
}
}
Расчет гороскопов и психоматрицы(квадрат Пифагора)
Этот код может помочь при разработке какого-нибудь астрологического или нумерологического софта.
int ostHoroscope(int n){
while (n>12){
n-=12;
}
return n;
}
int zodiac(int n,int month){
int f;
if (month==3&&n>20||month==4&&n<21)f=1;
else if (month==4&&n>20||month==5&&n<22)f=2;
else if (month==5&&n>21||month==6&&n<22)f=3;
else if (month==6&&n>21||month==7&&n<23)f=4;
else if (month==7&&n>22||month==8&&n<22)f=5;
else if (month==8&&n>21||month==9&&n<24)f=6;
else if (month==9&&n>23||month==10&&n<24)f=7;
else if (month==10&&n>23||month==11&&n<23)f=8;
else if (month==11&&n>22||month==12&&n<23)f=9;
else if (month==12&&n>22||month==1&&n<21)f=10;
else if (month==1&&n>20||month==2&&n<20)f=11;
else if (month==2&&n>19||month==3&&n<21)f=12;
else return 13;
return f;
}
|
|
int slavian(int n,int month){
int f;
if (month==3&&n>9||month==4&&n<11)f=1;
else if (month==4&&n>9||month==5&&n<11)f=2;
else if (month==5&&n>9||month==6&&n<11)f=3;
else if (month==6&&n>9||month==7&&n<11)f=4;
else if (month==7&&n>9||month==8&&n<11)f=5;
else if (month==8&&n>9||month==9&&n<11)f=6;
else if (month==9&&n>9||month==10&&n<11)f=7;
else if (month==10&&n>9||month==11&&n<11)f=8;
else if (month==11&&n>9||month==12&&n<11)f=9;
else if (month==12&&n>9||month==1&&n<11)f=10;
else if (month==1&&n>9||month==2&&n<11)f=11;
else if (month==2&&n>9||month==3&&n<11)f=12;
else return 13;
return f;
}
int egypt(int n,int month){
int f;
if (month==1&&n>0&&n<8||month==6&&n>18&&n<29||month==9&&n>0&&n<8||month==11&&n>17&&n<27)f=1;
else if (month==1&&n>7&&n<22||month==2&&n>0&&n<12)f=2;
else if (month==1&&n>21&&n<32||month==9&&n>7&&n<23)f=3;
else if (month==2&&n>11&&n<30||month==8&&n>19&&n<32)f=4;
else if (month==3&&n>10&&n<32||month==10&&n>17&&n<30||month==12&&n>18&&n<32)f=5;
else if (month==3&&n>0&&n<11||month==11&&n>26||month==12&&n<19)f=6;
else if (month==4&&n>0&&n<20||month==11&&n>7&&n<18)f=7;
else if (month==5&&n>0&&n<8||month==4&&n>19&&n<31||month==8&&n>11&&n<20)f=8;
else if (month==5&&n>7&&n<28||month==6&&n>28||month==7&&n<14)f=9;
else if (month==5&&n>27||month==6&&n<19||month==9&&n>27||month==10&&n<3)f=10;
else if (month==7&&n>13&&n<29||month==9&&n>22&&n<28||month==10&&n>2&&n<18)f=11;
|
|
else if (month==7&&n>28||month==8&&n<12||month==10&&n>29||month==11&&n<8)f=12;
else return 13;
return f;
}
String psychoMatrix(int n,int m,int l){
int[]mas=new int[16];
mas[0] = n / 10;
mas[1] = n % 10;
int c;
int z;
if (mas[0] == 0)
{
c= mas[1];
} else
{
c= mas[0];
}
mas[4]= m % 10;
z = m / 10;
mas[5] = z % 10;
z = z / 10;
mas[6] = z % 10;
z = z / 10;
mas[7]=z;
if(l<10){
mas[2]=0;
mas[3]=l;
}else{
mas[2]=1;
mas[3]=l-10;
}
int sum = mas[0] + mas[1] + mas[2] + mas[3] + mas[4] + mas[5] + mas[6] + mas[7];
mas[8] = sum/ 10;
mas[9] = sum % 10;
mas[10] = (mas[8]+mas[9])/ 10;
mas[11] = (mas[8]+mas[9])% 10;
mas[12] = (sum-(2*c)) / 10;
mas[13] = (sum-(2*c)) % 10;
mas[14] = (mas[12]+mas[13]) / 10;
mas[15] = (mas[12]+mas[13]) % 10;
String str1="",str2="",str3="",str4="",str5="",str6="",str7="",str8="",str9="";
for (int i=0;i<16;i++){
switch (mas[i]){
case 0:break;
case 1:str1+="1";break;
case 2:str2+="2";break;
case 3:str3+="3";break;
case 4:str4+="4";break;
case 5:str5+="5";break;
case 6:str6+="6";break;
case 7:str7+="7";break;
case 8:str8+="8";break;
case 9:str9+="9";break;default:break;
}
}
return "Психоматрица: \n"+str1+" "+str2+" "+str3+"\n"+str4+" "+str5+" "+str6+"\n"+str7+" "+str8+" "+str9;
}
Дата добавления: 2019-02-12; просмотров: 122; Мы поможем в написании вашей работы! |
Мы поможем в написании ваших работ!