格式不好,再发一个看看class Estazolam { public static void main(String[] args) { int i = 1; for(int j = 1; i <=100; j++) { int k = 0; while(k++ < j && i <= 100) { System.out.print(" " + i++); } System.out.println(); } } }
class Estazolam { public static void main(String[] args) { int j = 1; for(int i = 1; i <=100; i++) { int k = 0; if(k < j) { System.out.print(" " + i++); } else { System.out.println(); j++; } } } }
3楼的代码我咋觉得是错的呢public class Test { public static void main(String[] args) { int j = 1; int k = 0; for(int i = 1; i <=100; i++) { if(k < j) { System.out.print(" " + i); k++; } else { System.out.println(); i--; j++; k = 0; } } } }
这个输出格式美观些public class Test { public static void main(String[] args) { int j = 1; int k = 0; for (int i = 1; i <= 100; i++) { if (k < j) { System.out.print(i + "\t"); k++; } else { System.out.println(); i--; j++; k = 0; } } } }
int max = 1; for(int i=1;i<100;i++){ for(int n=1;n<=max;n++){ if(n == 1){ System.print(i); }else if(n == max && max != 1){ System.println("," + String.valueof(i)); }else{ System.print("," + String.valueof(i)); } } }
public class One2Hundred{ public static void main(String[] args) { int i = 1; int count = 0;
public class Hundred { public static void main(String[] args) { int i, j, m, n; j = 0; m = 0; n = 100; for (i = 1; i <= n; i++) { System.out.printf("%02d ", i); if (++j > m) { System.out.println(""); j = 0; m++; } } } }
我的:献丑了
package test;public class DateShow { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int i=0;//行数 int k=100;//要显示的最大的数据 int sum=0; int col=0; //求总共有多少行的 //1--n行的等差数列的和等于第一行的最后一个数 for(i=0;i<k;i++) { sum=sum+i;
void abc() { int tmp = 0; int changeLine = 1; for (int i = 1; i <= 100; i++) { System.out.print(i + "\t"); if (i == changeLine + tmp) { System.out.println(); tmp = i; changeLine++; } } }
public static void getSanjiaoXing(int n) { int i = 1; int row = 1; while (i <= n) { for (int j = 0; j < row; j++) { System.out.printf("%-2d", i++); // System.out.println(""); if (i > n) { break; }
} System.out.println(""); row++; }
}
public void print(int n){
int row = getLineNum(n,1,2); int num = 1; for(int i = 1 ;i<=row;i++){ int sp = ((2*row-1)-(2*i-1))/2; for(int j=1;j<=sp;j++){ System.out.print(" "); } for(int k=1;k<=2*i-1;k++){ if(num<10){ System.out.print("00"+num); }else if(num>9&&num<100){ System.out.print("0"+num); }else{ System.out.println(num); }
num++; } System.out.println(); } }
public int getLineNum(int sn,int a1,int d){ int n = 0; //sn = a1*n+n*(n-1)*d/2; int a = d/2; int b= a1-d/2; int c=-sn; n=(int) ((-b + Math.sqrt(Math.pow(b, 2) - 4*a*c))/(2*a)); return n; } 001 002003004 005006007008009 010011012013014015016 017018019020021022023024025 026027028029030031032033034035036 037038039040041042043044045046047048049 050051052053054055056057058059060061062063064 065066067068069070071072073074075076077078079080081 082083084085086087088089090091092093094095096097098099100结果。
public static void getSanjiaoXing(int n) { int i = 1; int row = 1; while (i <= n) { for (int j = 0; j < row; j++) { System.out.printf("%-2d", i++); // System.out.println(""); if (i > n) { break; }
} System.out.println(""); row++; }
}
不好意思啊 小弟第一次在csdn发帖 不懂规矩 下次不会了 大家都有份 ^_^
public class Hundred { public static void main(String[] args) { int i, j, m, n; j = 0; m = 0; n = 100; for (i = 1; i <= n; i++) { System.out.printf("%02d ", i); if (++j > m) { System.out.println(""); j = 0; m++; } } } }楼主三的方法很精炼
public class Test { static int num = 0; public static void main(String[] args) { int tagNum = 1000;
for (int i = 0; i < tagNum+1; i++) { for (int j = 0; j < i; j++) { System.out.print(++num+"\t"); if (num == tagNum) return; } System.out.print("\n"); if (num == tagNum) return; } } }
public class Out { public static void main(String[] args){ int count = 1; int count1 = 0; for(int i = 1;i<101;i++){ if(count1<count){ System.out.print(i+" "); count1++; }else{ count1 = 0; count++; i--; System.out.println(); } } } }
int n = 1; int cnt = 0; for (int i = 1; i <= 100; i++) { System.out.print(i+" "); cnt++; if(cnt == n){ n++; cnt = 0; System.out.println(); } }
class B { public static void print(int n){ int i = 1; int row = 0; while(i<=n){ for(int j=0;j<=row;j++){ System.out.print(i++); System.out.print(" "); if(i>n){ break; } } System.out.println(); row++; } } public static void main(String[] args) { B b = new B(); b.print(100); } }
也来凑个热闹…………public static void main(String[] args) { int j = 1; int k = 1; while(k<=100) { for(int i=1;i<=j;i++){ System.out.print(k++ + " "); if(k>100) break; } System.out.println(); j++; }
}
public static void main(String[] args) { int j = 1; int k = 1; while(k<=100) { for(int i=1;i<=j;i++){ System.out.print(k++ + " "); if(k>100) break; } System.out.println(); j++; }
}
public class TestNum { public static void main(String[] args){ int i = 1; //第i个数字 int j = 1; //第j行 int count = 1; //该行的第count个数字
class Estazolam { public static void main(String[] args) { int i = 1; for(int j = 1; i <=100; j++) { int k = 0; while(k++ < j && i <= 100) { System.out.print("*" + i++); } System.out.println(); } } }
public class Test11 { public static void main(String[] args) { Scanner input= new Scanner(System.in); System.out.print("输出一个数:"); int a=input.nextInt(); int count=0; for(int i=1;i<=a;i++){ for(int j=1;j<=i;j++){ count++;
public static void main(String[] args) {
int i = 1;
for(int j = 1; i <=100; j++) {
int k = 0;
while(k++ < j && i <= 100) {
System.out.print(" " + i++);
}
System.out.println();
}
}
}
public static void main(String[] args) {
int i = 1;
for(int j = 1; i <=100; j++) {
int k = 0;
while(k++ < j && i <= 100) {
System.out.print(" " + i++);
}
System.out.println();
}
}
}
class Estazolam {
public static void main(String[] args) {
int j = 1;
for(int i = 1; i <=100; i++) {
int k = 0;
if(k < j) {
System.out.print(" " + i++);
} else {
System.out.println();
j++;
}
}
}
}
public static void main(String[] args) {
int j = 1;
int k = 0;
for(int i = 1; i <=100; i++) {
if(k < j) {
System.out.print(" " + i);
k++;
} else {
System.out.println();
i--;
j++;
k = 0;
}
}
}
}
public static void main(String[] args) {
int j = 1;
int k = 0;
for (int i = 1; i <= 100; i++) {
if (k < j) {
System.out.print(i + "\t");
k++;
} else {
System.out.println();
i--;
j++;
k = 0;
}
}
}
}
for(int i=1;i<100;i++){
for(int n=1;n<=max;n++){
if(n == 1){
System.print(i);
}else if(n == max && max != 1){
System.println("," + String.valueof(i));
}else{
System.print("," + String.valueof(i));
}
}
}
public class One2Hundred{
public static void main(String[] args) {
int i = 1;
int count = 0;
for (int j = 1; j <= 100; j++) {
if (count < i) {
if (j < 10) {
System.out.print("0"+j +" ");
}else {
System.out.print(j + " ");
}
count++;
}else {
System.out.println();
count = 0;
i++;
j--;
}
}
}
}Result:
01
02 03
04 05 06
07 08 09 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63 64 65 66
67 68 69 70 71 72 73 74 75 76 77 78
79 80 81 82 83 84 85 86 87 88 89 90 91
92 93 94 95 96 97 98 99 100
print(2);print(" ");print(3);
.......
haha
public class Hundred {
public static void main(String[] args) {
int i, j, m, n; j = 0;
m = 0;
n = 100;
for (i = 1; i <= n; i++) {
System.out.printf("%02d ", i);
if (++j > m) {
System.out.println("");
j = 0;
m++;
}
}
}
}
package test;public class DateShow { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int i=0;//行数
int k=100;//要显示的最大的数据
int sum=0;
int col=0;
//求总共有多少行的
//1--n行的等差数列的和等于第一行的最后一个数
for(i=0;i<k;i++)
{
sum=sum+i;
if(sum>=k)
break;
}
int data=1;
System.out.println("-----------------------");
//按行输出数据
for(int j=1;j<=i;j++)
{
col=i-j;
if(col!=0)
System.out.printf("%"+col+"c", ' ');
for(int t=0;t<j&&data<=k;t++,data++)
if(data<10)
System.out.print("0"+data+" ");
else
System.out.print(data+" ");
System.out.println();
} }
} 01
02 03
04 05 06
07 08 09 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63 64 65 66
67 68 69 70 71 72 73 74 75 76 77 78
79 80 81 82 83 84 85 86 87 88 89 90 91
92 93 94 95 96 97 98 99 100
int tmp = 0;
int changeLine = 1;
for (int i = 1; i <= 100; i++) {
System.out.print(i + "\t");
if (i == changeLine + tmp) {
System.out.println();
tmp = i;
changeLine++;
}
}
}
int i = 1;
int row = 1;
while (i <= n) {
for (int j = 0; j < row; j++) {
System.out.printf("%-2d", i++);
// System.out.println("");
if (i > n) {
break;
}
}
System.out.println("");
row++;
}
}
public void print(int n){
int row = getLineNum(n,1,2);
int num = 1;
for(int i = 1 ;i<=row;i++){
int sp = ((2*row-1)-(2*i-1))/2;
for(int j=1;j<=sp;j++){
System.out.print(" ");
}
for(int k=1;k<=2*i-1;k++){
if(num<10){
System.out.print("00"+num);
}else if(num>9&&num<100){
System.out.print("0"+num);
}else{
System.out.println(num);
}
num++;
}
System.out.println();
}
}
public int getLineNum(int sn,int a1,int d){
int n = 0;
//sn = a1*n+n*(n-1)*d/2;
int a = d/2;
int b= a1-d/2;
int c=-sn;
n=(int) ((-b + Math.sqrt(Math.pow(b, 2) - 4*a*c))/(2*a));
return n;
}
001
002003004
005006007008009
010011012013014015016
017018019020021022023024025
026027028029030031032033034035036
037038039040041042043044045046047048049
050051052053054055056057058059060061062063064
065066067068069070071072073074075076077078079080081
082083084085086087088089090091092093094095096097098099100结果。
int i = 1;
int row = 1;
while (i <= n) {
for (int j = 0; j < row; j++) {
System.out.printf("%-2d", i++);
// System.out.println("");
if (i > n) {
break;
}
}
System.out.println("");
row++;
}
}
小弟第一次在csdn发帖
不懂规矩
下次不会了
大家都有份
^_^
public static void main(String[] args) {
int i, j, m, n; j = 0;
m = 0;
n = 100;
for (i = 1; i <= n; i++) {
System.out.printf("%02d ", i);
if (++j > m) {
System.out.println("");
j = 0;
m++;
}
}
}
}楼主三的方法很精炼
{
static int num = 0; public static void main(String[] args)
{
int tagNum = 1000;
for (int i = 0; i < tagNum+1; i++)
{
for (int j = 0; j < i; j++)
{
System.out.print(++num+"\t");
if (num == tagNum)
return;
}
System.out.print("\n");
if (num == tagNum)
return;
}
}
}
public static void main(String[] args){
int count = 1;
int count1 = 0;
for(int i = 1;i<101;i++){
if(count1<count){
System.out.print(i+" ");
count1++;
}else{
count1 = 0;
count++;
i--;
System.out.println();
}
}
}
}
for(int i=1,k=1;i<16;i++){
for(int j=0;j<20-i;j++){
System.out.print(" ");
}
for(int j=1;j<=2*i-1&&k<=100;j++){
if(j%2!=1){
System.out.print(" ");
} else {
System.out.print((k<10)?" "+k:k);
k++;
}
}
System.out.println();
}
}显示结果:
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 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63 64 65 66
67 68 69 70 71 72 73 74 75 76 77 78
79 80 81 82 83 84 85 86 87 88 89 90 91
92 93 94 95 96 97 98 99 100
int cnt = 0;
for (int i = 1; i <= 100; i++) {
System.out.print(i+" ");
cnt++;
if(cnt == n){
n++;
cnt = 0;
System.out.println();
}
}
{
public static void print(int n){
int i = 1;
int row = 0;
while(i<=n){
for(int j=0;j<=row;j++){
System.out.print(i++);
System.out.print(" ");
if(i>n){
break;
}
}
System.out.println();
row++;
}
}
public static void main(String[] args)
{
B b = new B();
b.print(100);
}
}
int j = 1;
int k = 1;
while(k<=100) {
for(int i=1;i<=j;i++){
System.out.print(k++ + " ");
if(k>100) break;
}
System.out.println();
j++;
}
}
int j = 1;
int k = 1;
while(k<=100) {
for(int i=1;i<=j;i++){
System.out.print(k++ + " ");
if(k>100) break;
}
System.out.println();
j++;
}
}
public static void main(String[] args){
int i = 1; //第i个数字
int j = 1; //第j行
int count = 1; //该行的第count个数字
while(i <= 91){
if(count < j){
System.out.print(i + " ");
count++;
}
else{
count = 1;
j++;
System.out.print(i + " ");
System.out.println();
}
i++;
}
}
}
public static void main(String[] args){
int i = 1; //第i个数字
int j = 1; //第j行
int count = 1; //该行的第count个数字
while(i <= 91){
if(count < j){
System.out.print(i + " ");
count++;
}
else{
count = 1;
j++;
System.out.print(i + " ");
System.out.println();
}
i++;
}
}
}
public static void main(String[] args) {
int i = 1;
for(int j = 1; i <=100; j++) {
int k = 0;
while(k++ < j && i <= 100) {
System.out.print("*" + i++);
}
System.out.println();
}
}
}
public static void main(String[] args) {
Scanner input= new Scanner(System.in);
System.out.print("输出一个数:");
int a=input.nextInt();
int count=0;
for(int i=1;i<=a;i++){
for(int j=1;j<=i;j++){
count++;
System.out.print(count);
if(j==i){
System.out.println();
}
}
if(count==a){
break;
}
} }}