سؤالات در مورد جاوا را در این تاپیک بپرسید
به نام خدا
کاربران گرامی می توانند در این تاپیک سؤالات خود در مورد برنامه نویسی به زبان جاوا را مطرح نمایند
سعی می شود در اسرع وقت به سؤالات پاسخ داده شود.
می خوام یه محدودیتی روی اعداد تصادفی آرایه ها اعمال کنم:
// Pick array size T from 1 to 100.
int T = 1 + myRand.nextInt(5);
System.out.println("T="+(T));
int C = 1 + myRand.nextInt(100);
System.out.println("C="+(C));
// Declare array of size T.
int [] production_cost=new int [T];
int []stock1= new int [T];
int[]stock2= new int [T];
int[]fix_cost1= new int [T];
int[]fix_cost2= new int [T];
int[] Demands=new int[T];
// Fill the array with random numbers.
{for (int i=0; i< T; i++){
production_cost[i] = myRand.nextInt(Integer.max(0,stock1+production_cost[i-1]));
stock1[i] = myRand.nextInt(Integer.max(0, 20));
stock2[i]= myRand.nextInt(Integer.max(0,20));
fix_cost1[i]=myRand.nextInt(Integer.max(10, 20) );
fix_cost2[i]=myRand.nextInt(Integer.max(20,30));
Demands[i] = myRand.nextInt(Integer.max(1,C));}
System.out.println("p2::"+Arrays.toString(production_cost));
System.out.println("h1::"+Arrays.toString(stock1));
System.out.println("h2::"+Arrays.toString(stock2));
System.out.println("K1::"+Arrays.toString(fix_cost1));
System.out.println("K2::"+Arrays.toString(fix_cost2));
System.out.println("d::"+Arrays.toString(Demands));
}}
}
با سلام
اگر بخواهم تابعی بنویسم که رشته ای از ورودی گرفته و آن را به ترتیب حروف الفبا مرتب کند به چه صورت است؟
رشته از طریق ورودی توسط کاربر گرفته میشود و با فراخوانی تابع مرتب میشود.
مثالfcbe
مرتب شده bcef