看了一些帖子突然想到之前有家面试出的一道编程题!!!愣是没想出来

Leno_Clown 2016-05-12 11:32:54
加精
求大神帮忙解答!
编程结果是这样的:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
...全文
5042 56 打赏 收藏 转发到动态 举报
写回复
用AI写文章
56 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_37330994 2017-03-04
  • 打赏
  • 举报
回复
Scanner s = new Scanner(System.in);
int nextInt = s.nextInt();
int a = 1;
int b = 2;
for (int i = 1; i <= nextInt; i++) {
System.out.print(i+"\t");
if(a==i){
System.out.println();
a=a+b;
b++;
};

}
stpilot 2017-01-23
  • 打赏
  • 举报
回复
好多大神啊,不明觉厉
beixian3367 2017-01-23
  • 打赏
  • 举报
回复
上面那个还不行?想到哪到哪啊
beixian3367 2017-01-23
  • 打赏
  • 举报
回复
public static void printNum(int maxNum){ int currNum = 1; int currEnd = 1; int addNum = 2; while(currNum<=maxNum){ System.out.print(currNum+"\t"); if(currNum>=currEnd){ System.out.println(); currEnd += addNum; addNum++; currNum++; }else{ currNum++; continue; } } } public static void main(String[] args) { NumberSort.printNum(30); } ———————————————————————————————————— 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
辐_射 2017-01-17
  • 打赏
  • 举报
回复
我这个还行吧
public static void main(String[] args) {
		int number = 1;
		for (int x = 0; x < 5; x++) {
			for (int y = 0; y < x+1; y++) {
				System.out.print(number++);
				System.out.print("\t");
			}
			System.out.println();
		}
	}
杂技猫 2016-12-20
  • 打赏
  • 举报
回复
public static void main(String[] args) { int i = 1; int t = 1; for(;i<=10;i++){ for(int c =1;c<=i;c++){ System.out.print(t++ +" "); } System.out.println(); } }
猴宝 2016-11-13
  • 打赏
  • 举报
回复
public static void suanFa(int n){ if (n <=1 && n >0) { System.out.println(n); return; } int result = 1; for (int i = 1; i <= n; i++) { int nie = result; for (int j = 1; j <= i; j++) { System.out.print(nie); System.out.print(" "); nie++; result = nie; } System.out.println(""); } }
mzplayo 2016-11-10
  • 打赏
  • 举报
回复
/** * 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... * @param number 需要显示出来的最大数字 */ public static void outPrint1(int number){ int num = 1; //计算行数 int count = 0; //第几个数 for(int i=1;i<=number;i++){ if(num == count){ System.out.println(); num++; count = 0; } System.out.print(i+" "); count++; } }
ZZZ3s326 2016-07-05
  • 打赏
  • 举报
回复
引用 15 楼 MinataYuuki 的回复:
public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.print("输入N的值:"); int n = in.nextInt(); int count = 1; int sum = 1; for(int i = 1; i <= n; i ++){ System.out.print(""+i+'\t'); if(sum == count){ System.out.println(); sum=1; count++; } sum++; } }
你的代码有问题
ZZZ3s326 2016-07-05
  • 打赏
  • 举报
回复

import java.util.Scanner;

public class testTest {  
    public static void main(String[] args)
    {
    	Scanner   scanner = new Scanner(System.in);
    	int num = scanner.nextInt();
    	int temp = 1;
    	
		for(int i = 1;temp<= num;i++)
		{
			for(int j = 1; j<=i&&temp<= num ;j++)
			{
				if(j == i||temp == num)
				{
					System.out.println(temp);
				}else {
					System.out.print(temp);
				}
				temp++;
			}
		}
    	
    }
}  
xyp6272453 2016-06-17
  • 打赏
  • 举报
回复
这个还用双循环就没意思了
qq_35067717 2016-05-20
  • 打赏
  • 举报
回复
int len = 16;//长度
int row = 1;//在第几行打印
int col = 1;//在第几列打印
for(int i=1;i<=len;i++){
System.out.print(i+"\t");
col++;
if(col>row){
System.out.println();
row++;//行加1时
col=1;//列归一
}
}
风致岚珊 2016-05-20
  • 打赏
  • 举报
回复
public class Demo3 { public static void main(String[] args) { boolean bool=true;//设置一个开关 int num=0; int end=23;//一共要输出多少个 for(int i=0;;i++){//死循环,可以无限输出 for(int j=0;j<=i;j++){ System.out.print(++num+"\t");//每一行都打印num的值 if(num==end){//判断相等,结束打印行的循环 bool=false; break; } } if(!bool){//如果bool是false,结束死循环 break; } System.out.println();//每次打印完一行换行 } } }
奄灬苟且偷生 2016-05-19
  • 打赏
  • 举报
回复
这道题已经40楼了,你们去解决点难的吧,这个没意思
qq_35048471 2016-05-19
  • 打赏
  • 举报
回复
Sub celia() x = 1 For i = 1 To 4 For j = 1 To i Cells(i, j) = x x = x + 1 Next Next End Sub
jike778 2016-05-19
  • 打赏
  • 举报
回复
引用 3 楼 qnmdcsdn 的回复:
int n = 4;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= i; j++) {
				int k = i - j + 1;
				int value = i + (k - 1) * n - k * (k - 1) / 2;
				System.out.print(value + " ");
			}
			System.out.print("\n");
		}
给你贴一个之前别人写的倒排的,觉得你这要求比这个简单多了
请问能说一下那value,k的公式思路吗?
xayzmb 2016-05-19
  • 打赏
  • 举报
回复
第几行就放几个数 循环......
youxiaoya73 2016-05-19
  • 打赏
  • 举报
回复
关键可能是要考虑到空格大小的计算吧
  • 打赏
  • 举报
回复
顺手写了个

var row=5;var _row=1;var temp=1;var l=0;var str="";while(_row<=row){str=str+temp+++" ";l++;if(l>=_row){l=0;_row++;str=str+"\n";} }console.log(str)
lm_whales 2016-05-18
  • 打赏
  • 举报
回复
求出最大数字占用的字节数 然后得出 每个数字占用的字节数,加上若干空格 然后输出即可
加载更多回复(34)

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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