❶ java 中,怎麼列印出一個字元串的所有排列
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
String str = "";
Scanner scan = new Scanner(System.in);
str = scan.nextLine();
permutation(str.toCharArray(), 0);
}
public static void permutation(char[] str, int i) {
if (i >= str.length)
return;
if (i == str.length - 1) {
System.out.println(String.valueOf(str));
} else {
for (int j = i; j < str.length; j++) {
char temp = str[j];
str[j] = str[i];
str[i] = temp;
permutation(str, i + 1);
temp = str[j];
str[j] = str[i];
str[i] = temp;
}
}
}
}
❷ 用java編寫程序顯示字元編排圖案
publicclassTest2014112005{
publicstaticvoidmain(Stringargs[]){
String[][]strs=newString[][]{
{"","","","J","","","","","A","","","","V","","","","","","V","","","","","A","","",""},
{"","","","J","","","","A","","A","","","","V","","","","V","","","","","A","","A","",""},
{"J","","","J","","","A","A","A","A","A","","","","V","","V","","","","","A","A","A","A","A",""},
{"","J","J","","","A","","","","","","A","","","","V","","","","","A","","","","","","A"},};
for(inti=0;i<strs.length;i++){
for(intj=0;j<strs[i].length;j++){
System.out.print(strs[i][j]);
}
System.out.println();
}
}
}
這?
❸ 在java中數字的平方怎樣表示
在Java中,求一個數平方,可以:
tmp = n*n;
Math.pow(n,2)
拓展資料:平方是一種運算,比如,a的平方表示a×a,簡寫成a²,也可寫成a×a(a的一次方乘a的一次方等於a的2次方),例如4×4=16,8×8=64,平方符號為2。
❹ java中如何顯示字元串位置
java中輸出字元所在位置可以使用indexOf()函數
例子:
System.out.println("abcd".indexOf("b"));
結果輸出1
返回b字元在字元串abcd中第一次出現的位置
❺ java的平方表達式怎麼寫
「java」的平方表達式是pow (double x,double y)。
函數原型:double pow (double x,double y)。
功能:返回x的y次方。
如要在java中求9的平方,可寫作double pow(double 9,double 9)。
❻ java 輸入一個字元串,列印出該字元串中字元的所有排列
實現思路:就是輸入字元串後,通過遞歸的方式,循環每個位置和其他位置的字元。
importjava.util.Scanner;
publicclassDemo001{
publicstaticvoidmain(String[]args){
Stringstr="";
Scannerscan=newScanner(System.in);
str=scan.nextLine();
permutation(str.toCharArray(),0);
}
publicstaticvoidpermutation(char[]str,inti){
if(i>=str.length)
return;
if(i==str.length-1){
System.out.println(String.valueOf(str));
}else{
for(intj=i;j<str.length;j++){
chartemp=str[j];
str[j]=str[i];
str[i]=temp;
permutation(str,i+1);
temp=str[j];
str[j]=str[i];
str[i]=temp;
}
}
}
}
❼ java中怎麼給一個字元串弄平方呢比如要把讓x這個字元串帶上平方,用Math.pow(double,double).
public static double pow(double a,double b) 官方文檔就是這么定義的,你可以先把String類型轉為double類型,再進行平方啊