Boollean (rush)

i cant produce an exact output

Page 1 of 1

3 Replies - 745 Views - Last Post: 13 August 2008 - 07:35 AM Rate Topic: -----

#1 qaz1134   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 121
  • Joined: 21-May 08

Boollean (rush)

Posted 31 July 2008 - 06:34 AM

hello guys cant you help me why cant i produce this ouput?

while should be true if 2
do while should be true if 3
and for should be true if 4
else all is falls\

import java.util.*;
import java.io.*;

public class Test {

	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader (new InputStreamReader (System.in));
		String input;
		int x;
		
			System.out.println("Number of Rows:\t");
			x = Integer.parseInt (input = in.readLine());
			
				
				for(int a=1;a<=x;a++)
				{
				
					System.out.print(a+"\tfor");	if((x%2)==1)System.out.print("\tTrue\n"); else System.out.print("\tFalse\n");
				
					
					do{
						a++;
						System.out.print(a+"\tdo while"); if((x%2)==0)System.out.print("\tTrue\n"); else System.out.print("\tFalse\n");
						
						while(a<=x)
						{
							a++;
							System.out.print(a+"\twhile"); if((x%2)==1)System.out.print("\tTrue\n"); else System.out.print("\tFalse\n");
							
							break;
						}
					break;}while(a<=x);
					
					
					
				}
			
			
  
 
	}
	
	
}


Is This A Good Question/Topic? 0
  • +

Replies To: Boollean (rush)

#2 lordms12   User is offline

  • D.I.C Regular
  • member icon

Reputation: 30
  • View blog
  • Posts: 339
  • Joined: 16-February 08

Re: Boollean (rush)

Posted 31 July 2008 - 11:50 AM

I do not what do you mean but are you sure from break at lines 36, 39
import java.util.*;
import java.io.*;

public class Test {

	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader (new InputStreamReader (System.in));
		String input;
		int x;

		System.out.println("Number of Rows:\t");
		x = Integer.parseInt (input = in.readLine());


		for(int a=1;a<=x;a++){
			System.out.print(a+"\tfor");
			if((x%2)==1)
				System.out.print("\tTrue\n"); 
			else 
				System.out.print("\tFalse\n");
			do{
				a++;
				System.out.print(a+"\tdo while"); 
				if((x%2)==0)
					System.out.print("\tTrue\n"); 
				else 
					System.out.print("\tFalse\n");

				while(a<=x){
					a++;
					System.out.print(a+"\twhile"); 
					if((x%2)==1)
						System.out.print("\tTrue\n"); 
					else 
						System.out.print("\tFalse\n");
					break;
				}
				
				break;
			}while(a<=x);
		}
	}
}

Was This Post Helpful? 0
  • +
  • -

#3 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Boollean (rush)

Posted 31 July 2008 - 05:05 PM

lordsms12 is right... why making a while statement if you break anyhow at the first iteration

                while(a<=x){  
                    a++;  
                    System.out.print(a+"\twhile");   
                    if((x%2)==1)  
                        System.out.print("\tTrue\n");   
                    else   
                        System.out.print("\tFalse\n");  
                    break;  
                }  


Was This Post Helpful? 0
  • +
  • -

#4 qaz1134   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 121
  • Joined: 21-May 08

Re: Boollean (rush)

Posted 13 August 2008 - 07:35 AM

View Postpbl, on 31 Jul, 2008 - 05:05 PM, said:

lordsms12 is right... why making a while statement if you break anyhow at the first iteration

                while(a<=x){  
                    a++;  
                    System.out.print(a+"\twhile");   
                    if((x%2)==1)  
                        System.out.print("\tTrue\n");   
                    else   
                        System.out.print("\tFalse\n");  
                    break;  
                }  




i guess you dont get my piont oever there (.)

if you dont put break there the loop will be endless if you dont put breaks onthe while nor the do while a will always be less than x

i want to make it like it act as a single loop.....
hope you understand
tnx for helping i kinnda figure out the answer anyway :D :D :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1