And you can solve it by tomorrow. We won't give you the answer, jos gave you the answer for the helper method. Try using it then use his math, re read his post If you need.

Printable View

- 03-06-2011, 02:42 PMsunde887
And you can solve it by tomorrow. We won't give you the answer, jos gave you the answer for the helper method. Try using it then use his math, re read his post If you need.

- 03-06-2011, 02:51 PMarunjib
thanks to all who is with me to solve my problem. i cannot think more right now. i shall try it later. hope i shall be able to solve this problem with your hints given

- 03-08-2011, 08:06 AMarunjib
I have made a code to print the pattern as

*****

****

***

as follows

Code:`import java.io.*;`

public class pattern1

{

public static void main (String[] args) throws IOException

{

InputStreamReader read = new InputStreamReader(System.in);

BufferedReader in = new BufferedReader(read);

int i,j,n=0,k;

System.out.print("How many stars you want to print in first row ? ");

n=Integer.parseInt(in.readLine());

for (i = 0; i<n; i=i+2)

{

for (j=i; j<n;j++)

System.out.print ("*");

System.out.println();

}

}

}

Please help me. - 03-10-2011, 01:40 PMarunjib
This is a code as an example of Math.ceil() method. But i don't know what library class should add for this method. please help me...

Code:`public class mathceil`

{

public static void main(String args[])

{

int n=31,x;

x=Math.ceil(n/2);

System.out.print(x);

}

}

- 03-10-2011, 01:44 PMsunde887
Your question is too vague. Do you mean what do you need to import? If that's the question, nothing the math class is part of java.lang which is automatically imported for you.

- 03-10-2011, 01:55 PMarunjib
- 03-10-2011, 02:00 PMsunde887
Integer division of 31/2 is 15. Play around with the code. What happens if you cast n to double? How bout if you divide by 2.0? Try both and see how they work. If it works, take a moment to think what the problem was.

- 03-10-2011, 02:06 PMarunjib
yes i have taken x as int. that was the wrong. i have to take x as double. thanks for hint. now i have another question. can i get output as 15 in case of 15.0 with the following code?

Code:`public class mathceil`

{

public static void main(String args[])

{

int n=31;

double x;

x=Math.ceil(n/2);

System.out.print(x);

}

}

- 03-10-2011, 02:08 PMsunde887
You can with a cast, I'll let you figure out where the cast goes

- 03-10-2011, 02:10 PMarunjib
- 03-10-2011, 02:15 PMsunde887
Cast is not a personal term, it's a have term. A cast allows you to cast one type to another. Try googling java cast.

- 03-10-2011, 02:17 PMarunjib
- 03-10-2011, 02:18 PMJosAH
- 03-10-2011, 02:21 PMsunde887
- 03-10-2011, 02:37 PMarunjib
- 03-10-2011, 02:40 PMsunde887
Alright, perhaps that's what you are looking for. Play around with casting variables and see what happens.

- 03-10-2011, 02:42 PMJosAH