Ques. How can I store 00 as a value?

- Given integer n. How can I store the value n for n * 0s. e.g. n = 2 = 00

char [] seq = new char [1];

seq[0] = (char) (0 * n);

System.out.println(seq[0]); // If n is 2 should print 00

Posted on Jul 12, 2014 by adam
Ans. You can't represent something that will print as N zeros using a single character, or as an array consisting of a single character.

You need to use an alternative representation. The most obvious ideas are:

Use a character array with multiple characters, using one character slot for each zero. (You still won't be able to print a char[] directly using println ... but there are other ways to do it.)
Use a String, or a StringBuilder to represent the sequence of zeros.
Posted on Jul 12, 2014 by Arindam

Enter your Answer

Name
Email Address
Answer