算法与程序设计
发布网友
发布时间:2022-04-26 15:17
我来回答
共2个回答
热心网友
时间:2022-05-01 23:19
1.
public class TestRandomArray
{
public static void main(String[] args)
{
int maxline = (int) (Math.random()*100);
int[] array = new int[maxline];
for(int i=0;i<maxline;i++)
{
int temp = (int) (Math.random()*100);
if(temp>=10&&temp<=99)
{
array[i] = temp;
}
else
i--;
}
for(int j=0;j<maxline;j++)
{
int max = array[0];
if(array[j]>max)
{
max=array[j];
array[j] = array[0];
array[0] = max;
}
}
for(int k=0;k<maxline;k++)
{
System.out.print(array[k]+" ");
}
}
}
2.
public class TestNumber100
{
public static void main(String[] args)
{
for(int i=1;i<100;i++)
{
if(i%3==0&&(i%5!=0)&&(i%9!=0))
System.out.println(i+" ");
else
continue;
}
}
}
3.貌似没结果
public class Test3
{
public static void main(String[] args)
{
/*for(int i=0;i<=9;i++)
{
for(int j=0;j<=9;j++)
{
int code = 10000+i*1000+j*100+23;
if((code%57)==0&&(code%67)==0&&i!=j)
{
System.out.println("x="+i+","+"y="+j);
}
else
System.out.println(i+" "+j);
}
}*/
for(int i=10023;i<=19923;i++)
if(i==0&&i==0)
System.out.println(i+" ");
}
}
4.
class Caculate {
int money;
Caculate(){
money = 10;
}
public int charge (int distance){
if (distance < 3){
money = 10;
}
if ((distance >= 3) && distance < 15)
{
money = money + 2*(distance-3);
}
if (distance > 15 )
{
money = money + 2*12 + 3*(distance - 15);
}
return money;
}
public static void main(String args[]) {
System.out.println("请输入公里数");
int distance_example=0;
Scanner key = new Scanner(System.in);
int n = key.nextInt();
distance_example = n;
Caculate pay = new Caculate();
pay.money = pay.charge(distance_example);
System.out.println("You need to pay money:"+pay.money+" distance is:"+distance_example);
}
}
5.
public class Test4
{
public static void main (String args[])
{
int n=100;
while(n<=1000)
{
int i,j,k;
i=n/100;
j=(n-i*100)/10;
k=n%10;
if((Math.pow(i, 3)+Math.pow(j, 3)+Math.pow(k, 3))==n)
System.out.print(n+String.valueOf('\t'));
n++;
}
}
}
6.
public class TestMoney
{
public static void main(String[] args)
{
int one=1,two=2,five=5;
for(int i=1;i<100;i++)
for(int j=1;j<50;j++)
for(int k=1;k<20;k++)
{
if((i*one+j*two+k*five)==100)
System.out.println(i+"个一分,"+j+"个两分,"+k+"个五分");
}
}
}
7.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class TestJieCheng
{
public static void main (String args[])
{
int a=0,b=1;float sum=0;
System.out.print("请输入要计算的阶乘:");
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
a=Integer.parseInt(in.readLine());
}catch(IOException e){}
for(int i=1;i<=a;i++)
{
b=b*i;
}
System.out.print(a+"的阶乘是"+b);
}
}
7.
public class XXX{
public static void main()
{
for(int i=1 i<=10;i++)
{
int j,sum;
j=math(i);
sum+=j;
}
int math(int i){
int k=i;
int b=1;
for(int w=1;w<=k;w++)
{
b=b*w;
}
return b;
}
}
}
8.
public class Test4
{
public static void main (String args[])
{
int n=100;
while(n<=1000)
{
int i,j,k;
i=n/100;
j=(n-i*100)/10;
k=n%10;
if((Math.pow(i, 3)+Math.pow(j, 3)+Math.pow(k, 3))==n)
System.out.print(n+String.valueOf('\t'));
n++;
}
}
}
9.
public class TestNumber2
{
public static void main(String[] args)
{
final int maxline = 20;
double sum = 0;
double [] denominator = new double [maxline];
double [] numerator = new double [maxline];
for(int i=2;i<denominator.length;i++)
{
denominator[0]=1;
denominator[1]=2;
denominator[i]=denominator[i-1]+denominator[i-2];
}
for(int j=2;j<numerator.length;j++)
{
numerator[0]=2;
numerator[1]=3;
numerator[j]=numerator[j-1]+numerator[j-2];
}
for(int k=0;k<maxline;k++)
{
sum+=(numerator[k])/denominator[k];
}
System.out.println(sum);
}
}
10.
import java.io.*;
public class 根据输入的三个数求一元二次方程
{
public static void main (String args[]) throws NumberFormatException, IOException
{
float a[]=new float [3];
for(int i=0;i<a.length;i++)
{
System.out.println("请输入第"+(i+1)+"个数");
BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
a[i]=Float.parseFloat(in.readLine());
}
float x1=0,x2=0;
x1=(float) ((((-1)*a[1])+(Math.sqrt(a[1]*a[1]-4*a[0]*a[2])))/(2*a[0]));
x2=(float) ((((-1)*a[1])-(Math.sqrt(a[1]*a[1]-4*a[0]*a[2])))/(2*a[0]));
System.out.print(a[0]+"X2"+a[1]+"X"+a[2]+"的两个根是:");
System.out.print(x1+"和"+x2);
}
}
热心网友
时间:2022-05-02 00:37
给一楼的吧,人家都给你答出来了!!!!!!