...1:鸡翁一值钱五,鸡母一值钱三,鸡雏三值钱一。百钱买百鸡,问鸡翁...
发布网友
发布时间:2024-02-01 20:49
我来回答
共5个回答
热心网友
时间:2024-07-28 15:46
百钱买百鸡设3个变量就可以实现,排序嘛就用冒泡法最简单。
热心网友
时间:2024-07-28 15:45
public class test {
public static void main(String args[]){
for(int i = 0;i<21;i++){//公鸡
for(int j = 0;j<34;j++){//母鸡
int k = 100-j-i;
if((i+j+k==100)&&(15*i+9*j+k==300)){//因为int类型的数相除会舍弃余数,
//所以1/3为零,我让他们同时乘以3,没有分数
System.out.print("公鸡"+i+"\t");
System.out.print("母鸡"+j+"\t");
System.out.println("小鸡"+k+"\t");
}
}
}
热心网友
时间:2024-07-28 15:46
帮你写第二个吧。。。你的要求这么高,又不给分。
import java.util.Arrays;
public class InsertSort
{
public static void main(String[] args)
{
int[] a={14,2,5,1,6,9,456,8};
insertSort(a);
System.out.println(Arrays.toString(a));
}
public static void insertSort(int[] a){
int in,out,temp;
for(out=1; out<a.length; out++){
temp=a[out];
in=out;
while(in>0&&a[in-1]>=temp){
a[in]=a[in-1];
in--;
}
a[in]=temp;
}
}
}
热心网友
时间:2024-07-28 15:44
为了捡到钱。。。
import java.awt.Button;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class First {
public static void main(String[] args) {
first();//第一题
second();//第2个
third();//第3题
}
private static void third() {
final String reg = "[^0-9]*";
Frame f = new Frame("Third question");
Label first = new Label("Number1");
Label second = new Label("Number2");
final TextField num1 = new TextField(15);
final TextField num2 = new TextField(15);
f.add(first);//
f.add(num1);
f.add(second);
f.add(num2);
Button calc = new Button("Calculate");
final TextField result = new TextField();
calc.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {
if(num1.getText().matches(reg) || num2.getText().trim().matches(reg)){
result.setText("0");
return;
}
int number1 = Integer.parseInt(num1.getText());
int number2 = Integer.parseInt(num2.getText());
int min = Math.min(number1, number2);
int max = Math.max(number1, number2);
int sum = 0;
while(min <= max){
boolean isPrime = true;
for(int j = 2; j <= Math.sqrt(min); j++){
if(min % j == 0){
isPrime = false;
}
}
sum += isPrime? min: 0;
min++;
}
result.setText(String.valueOf(sum));
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
});
f.add(calc);
f.add(result);
f.addWindowListener(new WindowClose());
f.setLayout(new GridLayout(3, 2));
f.setVisible(true);
f.pack();
}
private static void second() {
int[] ary = {14, 2, 5, 1, 6, 9, 456, 8};
for(int i = 0; i < ary.length; i++){
int index = i;
for(int j = i; j < ary.length; j++){
if(ary[index] > ary[j]){
index = j;
}
}
if(i != index){
int temp = ary[index];
ary[index] = ary[i];
ary[i] = temp;
}
}
System.out.print("After sorting, the array is: ");
for(int i = 0; i < ary.length; i++){
System.out.print(ary[i] + ",");
}
}
private static void first() {
int money = 100;
int qty = 100;
for(int i = 0; i <= money /5; i++){
for(int j = 0; j <= money/3 + 1; j++){
int jichuQty = 100 - i - j;
if(jichuQty % 3 == 0){
if(i * 5 + j * 3 + (100 - i - j ) / 3 == qty){
System.out.println("jiWeng = " + i + ", jimu = " + j + ", jichu= " + jichuQty);
}
}
}
}
}
}
class WindowClose implements WindowListener{
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
}
热心网友
时间:2024-07-28 15:48
用啥语言都一个写法 。