Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
vampires number Eckel B. Thinking in Java
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { int ch[]= new int[4]; int old=0; for (int chislo=1001; chislo<9999; chislo++) if (chislo%10!=0) { ch[0]=Math.round(chislo/1000); ch[1]=Math.round(chislo/100)-ch[0]*10; ch[2]=Math.round(chislo/10)-ch[0]*100-ch[1]*10; ch[3]=chislo-Math.round(chislo/10)*10; for (int a=0;a<4;a++) for (int b=0;b<4;b++) for (int c=0;c<4;c++) for (int d=0;d<4;d++) if ((a!=b)&&(c!=d)&&(b!=c)&& (a!=d)&&(a!=c)&&(b!=d)&& (((ch[a]*10+ch[b])*(ch[c]*10+ch[d]))==chislo)) { if (old!=chislo) { System.out.println(chislo+" = "+ ch[a]+ch[b]+" * "+ch[c]+ch[d]); old=chislo; } } } } } // Eckel B. Thinking in Java //Еккель Философия Java стр.143 задача 24 /* old version import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { for (int chislo=1001; chislo<9999; chislo++) if(chislo%10!=0) { int ch1=Math.round(chislo/1000); int ch2=Math.round(chislo/100)-ch1*10; int ch3=Math.round(chislo/10)-ch1*100-ch2*10; int ch4=chislo-Math.round(chislo/10)*10; int a=((ch1*10+ch2)*(ch3*10+ch4)); int b=((ch1*10+ch3)*(ch2*10+ch4)); int c=((ch1*10+ch4)*(ch3*10+ch2)); int d=((ch4*10+ch1)*(ch2*10+ch3)); int e=((ch4*10+ch2)*(ch3*10+ch1)); int f=((ch4*10+ch1)*(ch3*10+ch2)); int g=((ch3*10+ch1)*(ch2*10+ch4)); int h=((ch2*10+ch4)*(ch3*10+ch1)); if (a==chislo) System.out.println(chislo+" "+ch1+ch2+" * "+ch3+ch4); else if ( b==chislo) System.out.println(chislo+" "+ch1+ch3+" * "+ch2+ch4); else if (c==chislo) System.out.println(chislo+" "+ch1+ch4+" * "+ch3+ch2); else if (d==chislo) System.out.println(chislo+" "+ch4+ch3+" * "+ch2+ch1); else if (e==chislo) System.out.println(chislo+" "+ch4+ch2+" * "+ch3+ch1); else if (f==chislo) System.out.println(chislo+" "+ch4+ch1+" * "+ch3+ch2); else if (g==chislo) System.out.println(chislo+" "+ch3+ch1+" * "+ch2+ch4); else if (h==chislo) System.out.println(chislo+" "+ch2+ch4+" * "+ch3+ch1); } } } */
run
|
edit
|
history
|
help
1
Charles Chung
JAVA # Klavyeden girilen ayın Mevsimini bulma
add static
http://stackoverflow.com/questions/23175927/how-to-clone-object-defined-by-interface
pattern of the day (code formatting fixed)
fortune
inheritance
pourWater
jb11.0 threads tick tock 1.0
Account JAVA Cpa