Title One: The thickness of a piece of paper is about 0.08mm, how many times after the fold can reach the height of Mt. Everest (8848.13 m)?
Double height=0.08;
for (int i=1;i>0;i++)
{
height*=2;
if (height>= (8848.13*1000))
{
System.out.println ("Fold times =" +i);
Break
}
}
Topic two: Calculate factorial of 5 5! What's the result?
int sum=1;
for (int i=1;i<=5;i++)
{
Sum*=i;
}
System.out.println ("factorial of 5 =" +sum);
Topic Three: Calculating 1+1/2!+1/3!+1/4!+ ... 1/20!=?
Double sum=1;
Double d=0;
for (int i=1;i<=20;i++)
{
for (int b = 1;b <= i;b++)
{
Sum*=b;
}
d+= (1/sum);
}
System.out.println ("1/1!+1/2!+1/3!+1/4!+ ... 1/20!= "+d);
Poor Lifting method
Title One: Print out all the "daffodils", the so-called "Narcissus number" refers to a three-digit number, the number of its members of the cubic and equal to the number itself. For example: 153 is a "narcissus number", because the 153=1 three times the square +5 of the three +3 Times Square.
int z=0;
for (int i=1;i<=9;i++)
{
for (int n=0;n<=9;n++)
{
for (int y=0;y<=9;y++)
{
int s= (i*100) + (n*10) +y;
int b= (i*i*i+n*n*n+y*y*y);
if (b==s)
{
z++;
System.out.println ("+z+" Method of "+s");
}
}
}
}
Title Two: Ancient Chinese mathematician Zhang Chujian in the "Calculation of the book" in a "hundred money to buy hundred chickens" problem, test instructions is this: 5 Money can buy a rooster, 3 money can buy a hen, 1 money can buy 3 chicks. Now buy 100 chickens with 100 cents, so how many cocks, hens and chicks are there? Please write a program implementation.
int x, y, Z;
int s=0;
for (x=0;x<=20;x++)
{
for (y=0;y<=33;y++)
{
for (z=0;z<=100;z++)
{
if ((x+y+z) ==100&& (X*5+Y*3+Z/3) ==100&& (z%3==0))
{
s++;
System.out.println ("s Method:" +x+ "only Rooster" +y+ "only Hen" +z+ "only Chicks");
}
}
}
}
Title Three: This is the classic "Hundred Horse Hundred Bear" problem, there are 100 horses, pack 100 of goods, Big horse carry 3, the horse carry 2, two small horse Pack 1 bear, ask have big, medium, pony each several horses?
int s=0;
for (int x=0;x<=33;x++)
{
for (int y=0;y<=50;y++)
{
for (int z=0;z<=100;z++)
{
if (z%2==0 && (x+y+z) ==100 && (X*3+Y*2+Z/2) ==100)
{
s++;
System.out.println ("+s+" method "+x+" "Da Ma" +y+ "Zhong Ma" +z+ "Pony");
}
}
}
}
Topic Four: Console output 99 multiplication table
Title Five: Console output triangles and diamonds
Topic Six: Console input age, according to age output different tips
Scanner sc=new Scanner (system.in);
System.out.println ("Please enter an Age:");
int Age=sc.nextint ();
if (age>60)
{
System.out.println ("You are old");
}
else if (age>30)
{
System.out.println ("You are middle-aged");
}
else if (age>18)
{
System.out.println ("You for Youth");
}
else if (age>13)
{
System.out.println ("You are a teenager");
}
Else
{
System.out.println ("You Are Children");
}
Topic Seven: Enter the radius of the circle, calculate and output the circumference and area of the circle
Scanner sr=new Scanner (system.in);
SYSTEM.OUT.PRINTLN ("Input radius:");
Double d=sr.nextdouble ();
Final double pi=3.1415;
Double x, y;
X=2*pi*r;
Y=pi*r*r;
System.out.println ("perimeter =" +x);
System.out.println ("area =" +y);
java-Conditional statement, loop statement practice