Amazing Ancii Code using Java



// Comment
package com.sabari;javascript:void(0);

publicclass AnciiCode {
	publicstaticvoid main(String[] args) {
		System.out.println("Ancii Code Using Java");
		for (int i = 32; i < 127; i++) {
		System.out.write(i);
		/*Line Break after each Character display
		 * Each tab space for until 8 character
		 * 
		 */
		if (i % 8 == 7) System.out.write('\n');
		else System.out.write('\t');
		}
		System.out.write('\n');
		}
}



The write() method sends a specific bit pattern to a specific output stream. The write() method usually writes a single unsigned byte of data whose value should be between 255. Suppose when we use number larger than 255 or smaller than zero, it's reduced modulo 256 before being written.

// Comment

package com.sabari;

publicclass AnciiCode {
	publicstaticvoid main(String[] args) {
		System.out.println("Ancii Code Using Java");
		for (int i = 32; i < 127; i++) {
		System.out.write(i);
		/*Line Break after each Character display
		 * Each tab space for until 8 character
		 * 
		 */
		if (i % 8 == 7) System.out.write(10);
		else System.out.write(9);
		}
		System.out.write('\n');
		}
}

Both program produce the same output because while compiling your program the compiler converts the literals ‘\t’ and ‘\n’ in to numeric value 9 and 10.when it come to console for printing .The Console converts 9 and 10 to ‘\t’ and ‘\n’ respectively.
Output
Ancii Code Using Java
      !     "     #     $     %     &     '
(     )     *     +     ,     -     .     /
0     1     2     3     4     5     6     7
8     9     :     ;     <     =     >     ?
@     A     B     C     D     E     F     G
H     I     J     K     L     M     N     O
P     Q     R     S     T     U     V     W
X     Y     Z     [     \     ]     ^     _
`     a     b     c     d     e     f     g
h     i     j     k     l     m     n     o
p     q     r     s     t     u     v     w
x     y     z     {     |     }     ~     
raja P Web Developer

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...