Topic: 一道招聘笔试题 |
Print this page |
1.一道招聘笔试题 | Copy to clipboard |
Posted by: zhongbangxing Posted on: 2007-05-18 15:17 编写一段以下面形式输出的代码: 1 A 2 BB 3 CCC …… 25 YYYYYYYYYYYYYYYYYYYYYYYYY 26 ZZZZZZZZZZZZZZZZZZZZZZZZZZ 27 012345678901234567890123456 |
2.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: aaarong Posted on: 2007-05-18 17:19 public class Example{ public static void main(String[] args){ char a=65; char array[][]=new char[28][28]; for(int i=1;i<=27;i++){ System.out.print(i+" "); if(i<27){ for(int j=1;j<=i;j++){ array[i][j]=a; System.out.print(array[i][j]); } }else{ if(i==27){ a=48; } for(int p=1;p<=i;p++){ array[i][p]=a; System.out.print(array[i][p]); a++; if(a>57){ a=48; } } System.out.println(); } System.out.println(); a++; } } } |
3.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: xatm092 Posted on: 2007-05-19 13:47 我的做法是 (前面略,我想给出主要片段就行了.) System.out.println("1 A"); System.out.println("2 BB"); ...(中间略,我想你明白我的意思了.) System.out.println("26 ZZZZZZZZZZZZZZZZZZZZZZZZZZ"); System.out.println("27 012345678901234567890123456"); |
4.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: informit Posted on: 2007-05-20 01:16 public class Example { public static void main(String[] args) { String s; for(int i=1, char c='A'; i<=26; i++, c++){ s = " "; for(int j=1; j<=i; j++) s = s + c; System.out.println(i + s); } System.out.println("27 0123456789101234567890123456"); } } |
5.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: 133xialiang Posted on: 2007-05-24 09:56 public class Text { public static void main(String args[]) { int x = 0; for (char c = 'A'; c <= 'Z'; c++) { x++; System.out.print(x + " "); for (int i = 0; i < x; i++) { System.out.print( c ); } System.out.println(); } System.out.print(x + 1 + " "); for (int i = 0; i <= x; i++) { System.out.print(i % 10); } } } |
6.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: flying_sun Posted on: 2007-05-28 15:53 import java.io.*; public class Testprint { public static void main(String args[]) { int i =1; String str="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; while(i< 27) { charprint testp = new charprint(i,str.charAt(i-1)); testp.printchar(); i ++; } System.out.println("27012345678901234567890123456"); } } class charprint{ int i; int j; char str; charprint(int num,char str1) { this.i = 0; this.j = num; this.str = str1; } public void printchar() { System.out.print(j ); while(i<j) { System.out.print(this.str); i ++; } System.out.println(); } } |
7.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: Jcat Posted on: 2007-06-01 10:35 支持 133xialiang |
8.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: simleebdg Posted on: 2007-06-01 11:40 当时做出来了,就可以了.呵呵.我也支持133xialiang啊 |
9.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: 133xialiang Posted on: 2007-06-13 15:14 我才发了几个贴,我学习java刚一年,还是个新手,有各位的支持,我信心就更大了。 |
10.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: liangzi232004 Posted on: 2007-06-13 18:32 4楼方法也行~~ |
11.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: Yang14 Posted on: 2007-07-11 02:55 //**打印图1A public class Print { static String[] s={"A","B","C","D","E","F","G", "H","I","G","K","L","M","N", "O","P","Q","R","S","T", "U","V","W","X","Y","Z", }; static void go(int i) { System.out.print; for(int m=0;m<i;m++) System.out.print(s[i-1]); System.out.println(); } public static void main(String[] args) { try { for(int l=1;l<27;l++) { go(l); } for(int x=0;x<27 { for(int y=0;y<10&&x<27;y++,x++) { System.out.print; } } } catch(Exception e) { } } } |
12.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: Yang14 Posted on: 2007-07-11 02:56 //**打印图1A public class Print { static String[] s={"A","B","C","D","E","F","G", "H","I","G","K","L","M","N", "O","P","Q","R","S","T", "U","V","W","X","Y","Z", }; static void go(int i) { System.out.print(i); for(int m=0;m<i;m++) System.out.print(s[i-1]); System.out.println(); } public static void main(String[] args) { try { for(int l=1;l<27;l++) { go(l); } for(int x=0;x<27;) { for(int y=0;y<10&&x<27;y++,x++) { System.out.print(y); } } } catch(Exception e) { } } } |
13.Re:一道招聘笔试题 [Re: 133xialiang] | Copy to clipboard |
Posted by: Yang14 Posted on: 2007-07-11 03:00 133xialiang wrote: 高手啊 看看我的真是惭愧 |
14.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: dorrenchen Posted on: 2007-07-12 23:09 尝尝我ruby的厉害。 actual code. <code> n = ?A - 1 (1..26).each{|i| puts "#{i} #{(i+n).chr*i} "} puts "27 " + (0..27).collect{|i| i%10}.to_s </code> some ruby explanation. <code> # some ruby language functions # # ?<X> return the ASCII code of the character # ?A => 65 # ?B => 66 # ?\n => 10 backspace ASCII code is 10 # # # <N>.chr returns the character from given ASCII code # 65.chr => "A" # 66.chr => "B" # 10.chr => "\n" # # # <STR>*<n> multiplies given string n times. # "ABC"*2 => ABCABC # # # ruby use "#{var}" syntax to print variable in a string # x = "abc" # puts "output: #{x}" => "output: abc" </code> |
15.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: dorrenchen Posted on: 2007-07-12 23:13 actual code.
some ruby explanation
|
16.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: wzymiller Posted on: 2007-07-21 22:30 public class Example { public static void main(String[] args) { char a=65; char array[][]=new char[26][26]; for(int i=0;i<=26;i++,a++) { //System.out.print(i+" "); if(i<26) { for(int j=0;j<=i;j++) { array[i][j]=a; System.out.print(array[i][j]); } }else { System.out.print("012345678901234567890123456"); } } } } |
17.Re:一道招聘笔试题 [Re: aaarong] | Copy to clipboard |
Posted by: xiaoping8411 Posted on: 2007-09-18 19:27 public class PrintNumberLetter{ public static void main(String[] args){ print(); } public static void print(){ int n=0; char a='A'; for(int i=1;i<=27;i++){ if(i<=9) System.out.print(i+" "); else System.out.print(i+" "); if(i<27){ for(int j=1;j<=i;j++){ System.out.print; } } else{ for(int k=0;k<27;k++){ if(n>9) n=0; System.out.print; n++; } } System.out.println(); a++; } } } |
18.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: long_5281 Posted on: 2007-11-08 16:32 public static void main(String[] args){ int k = 1; //定义变量用于打印字符A BB CCC..... int n = 1 ; //定义变量用于打印数字012345678901234567890123456 for(int i=65;i<=90;i++){//i=65表示是字符大写A i=90表示是字符大写Z byte b = (byte)i; for(int j=1;j<=k&&k<=26;j++){ System.out.print((char)b);//输出A BB CCC..... } k++; System.out.println(); } while(n<=3){ for(int j=0;j<=9;j++){ if(n==3&&j>6){ continue ; }else{ System.out.print(j); //输出012345678901234567890123456 } } n++; } } |
19.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: weiyidexuan Posted on: 2007-11-11 01:37 //@author ricky //package com.ricky.www public class Test{ public static void print(char c,int times){ System.out.print(c); if(times == 1){ System.out.println(); }else{ print(c,times - 1); } } public static void main(String[] args){ char i = 0; for(i = 'A' ; i <= 'Z' ; i ++){ int times = i - 'A' + 1; System.out.printf("%2d ",times ); print(i,times); } int times = i - 'A' + 1; System.out.print( times + " "); for(int j = 0 ; j < times ; j ++){ System.out.print(j % 10); } } } |
20.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: pubaolin Posted on: 2007-11-12 01:11 public class Untitled2 { public static void main(String[] args) { int cc='A'; int aa='Z'; int i=1; do{ for(int j=0;j<i;j++){ System.out.print((char)cc); } System.out.println(""); i++; cc++; }while(cc<=aa); for(int j=0;j<i;j++){ System.out.print(j%10); } } } |
21.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: chaostring Posted on: 2007-11-12 18:17 133xialiang 写得很不错,我也是初学java,向你学习。 借鉴你的代码,我修改了一小下。不知道哪种写法执行效率更高些,请高人指点一下。 public class Test{ public static void main(String[] args) { for (char c='A';c<='Z';c++){ for(int i=(int)'A'; i<=(int)c;i++){ System.out.print(c); } System.out.println(); } for (int i=(int)'A'; i<=(int)'Z'+1;i++){ System.out.print((i-(int)'A')%10); } } |
22.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: chaostring Posted on: 2007-11-12 19:03 这个应该更合理些,打印函数forprint()可以完成很多其他 用途 并且使得主函数看起来很简洁。 public class Test { public static void main(String[] args) { for (char c='A';c<='Z';c++){ forPrint(c,1); System.out.println(); } forPrint((char)((int)'Z'+1),2); } // 打印函数 forPrint() public static void forPrint(char n ,int k){ for(char i='A'; i<=n;i++){ if(k==1){ System.out.print(n); }else if(k==2){ System.out.print((i-'A')%10); } } } } |
23.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: dnorange Posted on: 2007-11-13 22:25 public class MianShi { public static void main(String[] args) { ShuChu js=new ShuChu(); js.xianShi(); } } class ShuChu { int xianShi() { int i=0,j=0; char ch='A'; for(i=1;i<28;i++) { for(j=0;j<i;j++) { if(i==27) { System.out.print(j%10); continue; } System.out.print(ch); } System.out.print("\n"); ch++; } return 0; } } |
24.Re:一道招聘笔试题 [Re: 133xialiang] | Copy to clipboard |
Posted by: newfish Posted on: 2008-10-06 13:51 133xialiang wrote: 真是惭愧啊,在下做java开发已经快2年了尚不能写出如此精练的代码. |
25.Re:一道招聘笔试题 [Re: aaarong] | Copy to clipboard |
Posted by: yusilong860815 Posted on: 2008-10-06 16:14 我也是支持133xialiang |
26.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: jackieban Posted on: 2009-04-24 16:26 public class ascII{ public static void main(String args[]){ for(char i='A'; i<='Z'; i++){ for(int j=0; j<i-'A'+1; j++){ System.out.print; } System.out.println(); } for(int i=0; i<=26; i++){ System.out.print(i%10); } System.out.println(); } } |
27.Re:一道招聘笔试题 [Re: zhongbangxing] | Copy to clipboard |
Posted by: 楚狂人 Posted on: 2009-05-29 15:48 public class T { public static void main(String[] args) { int count = 0; for(int i = (int)'A';i <= (int)'Z';i++ ) { ++count; System.out.print(count+" "); for(int j = 0;j < count;j++) { System.out.print((char)i); } System.out.println(""); } count += 1; System.out.print(count+" "); for(int i = 0;i < count;i++) { System.out.print(i%10); } } } /* 其实前面的输出都很简单,但是不明白最后的一行究竟有什么意图,所以加上去的比较牵强,感觉还是有那么一点点的不爽,呵呵。 */ |
28.Re:我的解法 [Re: zhongbangxing] | Copy to clipboard |
Posted by: bashenxiutian Posted on: 2009-07-26 13:58 public class Test { public static void show(int n) { // 字母部分 char element = 'A'; for (int i = 1; i < n; i++) { System.out.print(i + "\t"); for (int j = 1; j <= i; j++) { System.out.print(element); } element++; System.out.println(); } // 数字部分 System.out.print("27" + "\t"); for(int i=0; i<=26; i++){ System.out.print(i%10); } } public static void main(String[] args) { show(27); } } |
29.Re:一道招聘笔试题 [Re: 133xialiang] | Copy to clipboard |
Posted by: sunny9527 Posted on: 2009-07-30 17:02 133xialiang wrote: 精辟 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |