473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Converting for loop to while/do-while ?

What seems to be wrong with my program?

Expand|Select|Wrap|Line Numbers
  1. public class FooBizBaz {
  2.     public static void main(String []args){
  3. int num1;
  4. int num=1;
  5.  
  6. num1=num <= 50;
  7.  
  8.  
  9. System.out.println(num);
  10.  
  11.     do{System.out.print("foo");}
  12.     while((num%3)==0);
  13.  
  14.     do{System.out.print("biz"); }
  15.     while((num%5)==0);
  16.  
  17.     do{System.out.print("baz");}
  18.     while((num%7)==0);
  19.  
  20. number++;    
  21. }  
  22. }
here's what i made using for loop, and now i find it hard to convert it to do-while..
Expand|Select|Wrap|Line Numbers
  1. public class FooBizBaz{
  2. public static void main(String []args){
  3.  
  4.  for(int number=1; number <=50, number++)
  5. {
  6. System.out.println(number);
  7. if((number%3)==0){
  8. System.out.print("foo");
  9. }
  10. {
  11. if((number%5)==0){
  12. System.out.print("biz");
  13. }
  14. {
  15. if((number%7)==0){
  16. System.out.print("baz");
  17. }
  18. }
  19. }
  20. }
Help please? Thank you very much!
Feb 11 '10 #1

✓ answered by pbrockway2

Is this an assignment question? If so, it might pay to say what the question actually is.

It seems to me that you have converted the if statements into do loops. But the question would make more sense if you had been asked to convert the for loop into a do loop. (and leave the if statements alone.)

Expand|Select|Wrap|Line Numbers
  1. for(int ndx = 0; ndx < limit; ndx++) {
  2.   if(whatever) {
  3.     doSomethig();
  4.   }
  5. }
  6.  
  7. // is similar to
  8.  
  9. int ndx = 0;
  10. do {
  11.   if(whatever) {
  12.     doSomething();
  13.   }
  14.   ndx++;
  15. } while(ndx < limit);
  16.  

3 4343
hello are u looking for this

class TestCase
{
public static void main(String argv[]) throws Exception
{
int number=0;
do {
if((number%3)==0){
System.out.print("foo");
}
if((number%5)==0){
System.out.print("biz");
}

if((number%7)==0){
System.out.print("baz");
}
number++;
}while(number<=50);
}
}
Feb 11 '10 #2
You can use this code-----
__________________________________________________ _______________
public class foobizbaz
{
public static void main(String args[])
{
int number=1;
do
{
if(number%3==0)
System.out.println("foo");
else if(number%5==0)
System.out.println("biz");
else if(number%7==0)
System.out.println("baz");
number++;
}
while(number<=50);
}
}

__________________________________________________ _______________
Feb 11 '10 #3
pbrockway2
151 Expert 100+
Is this an assignment question? If so, it might pay to say what the question actually is.

It seems to me that you have converted the if statements into do loops. But the question would make more sense if you had been asked to convert the for loop into a do loop. (and leave the if statements alone.)

Expand|Select|Wrap|Line Numbers
  1. for(int ndx = 0; ndx < limit; ndx++) {
  2.   if(whatever) {
  3.     doSomethig();
  4.   }
  5. }
  6.  
  7. // is similar to
  8.  
  9. int ndx = 0;
  10. do {
  11.   if(whatever) {
  12.     doSomething();
  13.   }
  14.   ndx++;
  15. } while(ndx < limit);
  16.  
Feb 11 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Venkata C | last post by:
Hi! Does anyone here know of a way to goad DB2 into converting a correlated subquery to a non-correlated one? Does DB2 ever do such a conversion? We have a query of the form SELECT .. FROM A...
3
by: Andy | last post by:
Hi ! I have many simple, low-tech database applications spread throughout my organization that I developed in Access 2K.. Most have ODBC for Oracle connections ( read only ) to our principal...
4
by: Patrick.O.Ige | last post by:
Hi All, Can anybody help in converting the code below to VB.NEt thanks. I need the loop converted.. thanks Private Sub expandCollapseAllTreeviewNodes(ByVal nodes As TreeNodeCollection, ByVal...
11
by: Steve | last post by:
I'm hoping someone can help me out. I'm a newbie to vb.net still. I'm trying to convert the code below from VB6 to VB.NET. I'm not sure of the best way to go. This is basically a simple...
9
by: Coleen | last post by:
Hi All :-) I found the way to get my column sum (Thanks Cor I did it a little different, but the result is what I wanted) I used: dt_stat_report_3b.Columns.Add(New DataColumn("Sum",...
4
by: sal | last post by:
Greets, All Converting array formula to work with datatables/dataset tia sal I finally completed a formula I was working on, see working code below. I would like to change this code so it...
59
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when...
2
by: shenanwei | last post by:
DB2 V8.2 on AIX, type II index is created. I see this from deadlock event monitor. 5) Deadlocked Connection ... Participant no.: 2 Lock wait start time: 09/18/2006 23:04:09.911774 .........
5
by: SMichal | last post by:
Hi, how can I parse string "? 20.000" to double ?
9
by: Jeremy Kitchen | last post by:
Are there any library functions that can help me to do this? If necessary I can convert the string to a byte array. I don't want to have to write my own Hex conversion if it isn't necessary. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.