❶ 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类型,再进行平方啊