面试题

LoveJava520 2008-03-10 02:48:31
*
* * *
* * * * *
* * * * * * *


怎么实现??????????
...全文
316 29 打赏 收藏 转发到动态 举报
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
firefox_1983 2008-03-12
  • 打赏
  • 举报
回复

for (int i = 1; i < 5; i++) {
for (int j = 0; j < 4 - i; j++) {
System.out.print(" ");
}
for (int j = 0; j < 2 * i - 1; j++) {
System.out.print("*");
}
for (int h = 0; h < 4 - i; h++) {
System.out.print(" ");
}
System.out.println("");
}
zzkk_1980 2008-03-12
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 bao110908 的回复:]
Java codepublic class Test {

public static void main(String[] args) {
printTriangle(5, true);
printTriangle(5, false);
}

private static void printTriangle(int line, boolean isSolid) {
for(int i = 1; i <= line; i++) {
for(int j = - line + 1; j < i; j++) {
if(isSolid) {
System.out.print(i > Math.ab…
[/Quote]
OnlyLikeJava 2008-03-12
  • 打赏
  • 举报
回复
这个答案我最喜欢。哈哈。直接。
cb1156 2008-03-12
  • 打赏
  • 举报
回复
14楼好样的。
说不定别人公司就要求这样
livehejie 2008-03-12
  • 打赏
  • 举报
回复
感觉这个方法最好,最省力气 最简单看到内容,且不用任何算法和 数据结构的知识。
lindazch 2008-03-12
  • 打赏
  • 举报
回复
public class Aver {

public static void main(String[] args) {

for(int i=0;i<=4;i++){
for(int j=0;j<4-i;j++){
System.out.print(" ");
}

for(int j=0;j<2*i-1;j++){
System.out.print("*");

}
System.out.println();
}
}
}
samuelson1970 2008-03-12
  • 打赏
  • 举报
回复
简单就是美!
public class Test4 {
public static void main(String[] args) {
System.out.println(" *\n ***\n *****\n*******");
}
}
xiazhigen 2008-03-12
  • 打赏
  • 举报
回复

public class Zhi{
public static void main(String[] args){
int n=4;//要输出的排数
for(int i=0;i<=n;i++){
for(int j=2*n;j>i*2-1;j--){
System.out.print(" ");
}

for(int j=0;j<i*2-1;j++){
System.out.print("* ");
}
System.out.println();
}

}
}
xiazhigen 2008-03-12
  • 打赏
  • 举报
回复
public class Zhi{
public static void main(String[] args){
int n=4;//要输出的排数
for(int i=0;i<=n;i++){
for(int j=2*n;j>i*2-1;j--){
System.out.print(" ");
}

for(int j=0;j<i*2-1;j++){
System.out.print("* ");
}
System.out.println();
}

}
}
hmsuccess 2008-03-11
  • 打赏
  • 举报
回复
向火龙果学习,经典
zjhlht 2008-03-11
  • 打赏
  • 举报
回复
哈哈~~~~~~
强悍中的霸主~~~~~~~~

不过支持发面试题~~~~
cydp007 2008-03-11
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 fpwcs 的回复:]
public class Aver{

public static void main(String[] args) {
System.out.println(" *");
System.out.println(" ***");
System.out.println(" *****");

System.out.println("*******");
}

}
[/Quote]


还不如直接写一个 println.分四段..哈哈..
lindazch 2008-03-11
  • 打赏
  • 举报
回复
14楼....~_~
sky_ccy 2008-03-10
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 fpwcs 的回复:]
public class Aver{

public static void main(String[] args) {
System.out.println(" *");
System.out.println(" ***");
System.out.println(" *****");

System.out.println("*******");
}

}
[/Quote]

兄弟,,我支持你,,最直接,,像个男人,哈哈,,
ZHOUJIAOSHOU 2008-03-10
  • 打赏
  • 举报
回复
用两层三个for语句就可以解决

说下思路吧.因为各种语句还得你自己写

第一层用来控制打印的行数,也就是第一个for语句,二三语句包含在其中
第二层用来控制打印的列数,第二个for语句用来打印空格数,第三个for语句用来打印*号,二三两个语句是并列的
fpwcs 2008-03-10
  • 打赏
  • 举报
回复
public class Aver{

public static void main(String[] args) {
System.out.println(" *");
System.out.println(" ***");
System.out.println(" *****");

System.out.println("*******");
}

}
muyan9 2008-03-10
  • 打赏
  • 举报
回复
很基本的问题啊
学语言都有这个题吧

你把时间浪费了
ashutc 2008-03-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 healer_kx 的回复:]
Java code public static void main(String[] args) {


int a = 4;

for (int i = 0; i < a; ++i) {
for (int h = 0; h < a - i; ++h) {
System.out.print(" ");
}
for (int j = 0; j < 2 * i + 1; ++j) {

System.out.print("* ");
}
System.out.println();

[/Quote]
编辑图形理解
行:需要一种* 就用一个for
列:需要一种*加上一种“ ”就用两个for
2n-1是奇数
这样你就可以随便写出任何图形了

  • 打赏
  • 举报
回复
public class Test {

public static void main(String[] args) {
printTriangle(5, true);
printTriangle(5, false);
}

private static void printTriangle(int line, boolean isSolid) {
for(int i = 1; i <= line; i++) {
for(int j = - line + 1; j < i; j++) {
if(isSolid) {
System.out.print(i > Math.abs(j) ? "*" : " ");
}else{
System.out.print(i == Math.abs(j) + 1 || i == line ? "*" : " ");
}
}
System.out.println();
}
}
}
healer_kx 2008-03-10
  • 打赏
  • 举报
回复
用Basic的时候,可以指定从哪里开始打印,于是就不用里面的第一个循环了,。但是语句记不得了。

Qb里面有个Locate吧?
加载更多回复(9)

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧