Java簡單程式設計題訓練一
阿新 • • 發佈:2019-01-05
字串反轉
import java.util.*; public class Main{ public static void main(String[] args){ Scanner in =new Scanner(System.in); while(in.hasNext()){ String line=in.nextLine();//next()是遇到空格;nextLine()是遇到回車 StringBuffer sb=new StringBuffer(line); sb.reverse(); System.out.println(sb.toString()); } } }
倒三角輸出
public class Test {
public static void main(String[] args) {
int i = 0;
for (i = 7; i >= 1; i -= 2) {
for (int k = (7 - i) / 2; k >= 1; k--){
System.out.print(" ");
}
for (int j = i; j >= 1; j--){
System.out.print("*");
}
System.out.println();
}
}
}