Java Code 100 horse 100 Tiles

Source: Internet
Author: User

I gave two pieces a special write code a dedicated output look at the results with too much if

There's a simple one that doesn't use too much if judgment

Not write the comments on the knowledge points are in the blog I sent if still have not understand can leave a message to fill in the comments

code class: if judged by

/**
* Q: There are 100 horses with 100 pieces of tiles,
* Big horse can support 3 pieces of tile, the horse can hold 2 pieces of tile, three pony can support a tile, just the 100 horses, the 100 pieces of tile finished.
* Ask how many horses, how many horses, how many ponies?
*/
public class dai_ma{
public static void M1 () {
zhongzhi:for (int d=1; d <100; ++d) {//I represent Malaysia here
for (int z=1; z <100; ++z) {//I represent Zhong Ma here
for (double x=1; x < ++x) {//I represent pony here
if (d + z + x = = && 3*d + 2*z + X/3 = = 100) {
System.out.println ("The First answer:");
System.out.print ("Da Ma for:" + D + "horse");
System.out.print ("Medium Horse is:" + z + "horse");
System.out.println ("Pony for:" + x + "horse");
Break Zhongzhi;
}
}
}

}
}
public static void M2 () {
zhongzhi:for (int d=1; d <100; ++d) {//I represent Malaysia here
for (int z=1; z <100; ++z) {//I represent Zhong Ma here
for (double x=1; x < ++x) {//I represent pony here
if (d + z + x = = && 3*d + 2*z + X/3 = = 100) {
if (d! = 5.0) {
System.out.println ("Second answer:");
System.out.print ("Da Ma for:" + D + "horse");
System.out.print ("Medium Horse is:" + z + "horse");
System.out.println ("Pony for:" + x + "horse");
Break Zhongzhi;
}
}
}
}

}
}
public static void M3 () {
zhongzhi:for (int d=1; d <100; ++d) {//I represent Malaysia here
for (int z=1; z <100; ++z) {//I represent Zhong Ma here
for (double x=1; x < ++x) {//I represent pony here
if (d + z + x = = && 3*d + 2*z + X/3 = = 100) {
if (d! = 5) {
if (d! = 10) {
System.out.println ("The third Answer:");
System.out.print ("Da Ma for:" + D + "horse");
System.out.print ("Medium Horse is:" + z + "horse");
System.out.println ("Pony for:" + x + "horse");
Break Zhongzhi;
}
}

}
}
}

}
}
public static void M4 () {
zhongzhi:for (int d=1; d <100; ++d) {//I represent Malaysia here
for (int z=1; z <100; ++z) {//I represent Zhong Ma here
for (double x=1; x < ++x) {//I represent pony here
if (d + z + x = = && 3*d + 2*z + X/3 = = 100) {
if (d! = 5) {
if (d! = 10) {
if (d! = 15) {
System.out.println ("Fourth answer:");
System.out.print ("Da Ma for:" + D + "horse");
System.out.print ("Medium Horse is:" + z + "horse");
System.out.println ("Pony for:" + x + "horse");
Break Zhongzhi;
}
}

}

}
}
}

}
}
public static void M5 () {
zhongzhi:for (int d=1; d <100; ++d) {//I represent Malaysia here
for (int z=1; z <100; ++z) {//I represent Zhong Ma here
for (double x=1; x < ++x) {//I represent pony here
if (d + z + x = = && 3*d + 2*z + X/3 = = 100) {
if (d! = 5) {
if (d! = 10) {
if (d! = 15) {
if (d! = 20) {
System.out.println ("Fifth answer:");
System.out.print ("Da Ma for:" + D + "horse");
System.out.print ("Medium Horse is:" + z + "horse");
System.out.println ("Pony for:" + x + "horse");
Break Zhongzhi;
}else{
System.out.println ("There is no answer for four");
}

}
}

}

}
}
}

}
}
}

To view the result class:

/**
* Q: There are 100 horses with 100 pieces of tiles,
* Big horse can support 3 pieces of tile, the horse can hold 2 pieces of tile, three pony can support a tile, just the 100 horses, the 100 pieces of tile finished.
* Ask how many horses, how many horses, how many ponies?
*/
public class jie_guo{
public static void Main (string[] args) {
DAI_MA.M1 ();
DAI_MA.M2 ();
DAI_MA.M3 ();
DAI_MA.M4 ();
DAI_MA.M5 ();
}
}

Simple:

public class jian_dan{
static int c = 0;//statically variable
public static void Main (string[] args) {
M1 ();//Call M1 Method
}
public static void M1 () {//Declare static method
for (int d=1; d <100; ++d) {//this represents Malaysia
for (int z=1; z <100; ++z) {//This represents the Chinese horse
for (double x=1; x <100; ++x) {//This means pony
if (d + z + x = = && 3*d + 2*z + X/3 = = 100) {//Judge as true to execute the statement
c + = 1;//come in once and C add in assignment to C
System.out.println ("a" + C + "kind of Answer:");//c came in several times to prove that there were several correct answers.
System.out.println ("Da Ma has:" +d + "in the horse has:" +z + "Pony has:" + x);
}
}
}

}
}
}

Java Code 100 horse 100 Tiles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.