Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 300,494 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,859 people online right now. Registration is fast and FREE... Join Now!




count in two lines

 

count in two lines

villalandron

1 Jul, 2009 - 06:12 PM
Post #1

D.I.C Head
**

Joined: 24 Sep, 2008
Posts: 124

I am having problems with this program. I need to build a program that will demonstrate a loop that will print the following output by using two loops:.
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20

Here's what I have so far:

CODE


import java.util.Scanner;

public class TwoLines
{
   public static void main (String[ ] args)
   {
        Scanner keyboard = new Scanner(System.in);
                
        for (int number = 1; number <=10; number++)
        System.out.print("\t" + number);
        
        System.out.print("\n");
        
        for (int num = 11; num <= 20; num+=1)
        System.out.print("\t" + num);    
   }//end main method
}//end class



Thank you for your help!

User is offlineProfile CardPM
+Quote Post


pbl

RE: Count In Two Lines

1 Jul, 2009 - 06:17 PM
Post #2

Java Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 9,537



Thanked: 1126 times
Dream Kudos: 450
My Contributions
Qnd what is wrong with your code ?
User is offlineProfile CardPM
+Quote Post

computerfox

RE: Count In Two Lines

1 Jul, 2009 - 06:18 PM
Post #3

straight vegetarian kid
*****

Joined: 29 Jan, 2009
Posts: 3,772



Thanked: 48 times
Dream Kudos: 1700
My Contributions
QUOTE(villalandron @ 1 Jul, 2009 - 06:12 PM) *

I am having problems with this program. I need to build a program that will demonstrate a loop that will print the following output by using two loops:.
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20

Here's what I have so far:

CODE


import java.util.Scanner;

public class TwoLines
{
   public static void main (String[ ] args)
   {
        Scanner keyboard = new Scanner(System.in);
                
        for (int number = 1; number <=10; number++)
        System.out.print("\t" + number);
        
        System.out.print("\n");
        
        for (int num = 11; num <= 20; num+=1)
        System.out.print("\t" + num);    
   }//end main method
}//end class



Thank you for your help!


where's your question? unsure.gif

but just to let you know:
CODE

for (int number = 1; number <=10; number++)
System.out.print(number+" ");
        
System.out.print("\n");
        
for (int num = 11; num <= 20; num++)
System.out.print(num+" ");


hope that helps smile.gif

This post has been edited by computerfox: 1 Jul, 2009 - 06:20 PM
User is offlineProfile CardPM
+Quote Post

villalandron

RE: Count In Two Lines

1 Jul, 2009 - 07:59 PM
Post #4

D.I.C Head
**

Joined: 24 Sep, 2008
Posts: 124

QUOTE(computerfox @ 1 Jul, 2009 - 06:18 PM) *

QUOTE(villalandron @ 1 Jul, 2009 - 06:12 PM) *

I am having problems with this program. I need to build a program that will demonstrate a loop that will print the following output by using two loops:.
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20

Here's what I have so far:

CODE


import java.util.Scanner;

public class TwoLines
{
   public static void main (String[ ] args)
   {
        Scanner keyboard = new Scanner(System.in);
                
        for (int number = 1; number <=10; number++)
        System.out.print("\t" + number);
        
        System.out.print("\n");
        
        for (int num = 11; num <= 20; num+=1)
        System.out.print("\t" + num);    
   }//end main method
}//end class



Thank you for your help!


where's your question? unsure.gif

but just to let you know:
CODE

for (int number = 1; number <=10; number++)
System.out.print(number+" ");
        
System.out.print("\n");
        
for (int num = 11; num <= 20; num++)
System.out.print(num+" ");


hope that helps smile.gif


Honestly, I don't know why I made that question because after looking at the last post made me realize that I knew how to do that. Anyways, thank you for opening my eyes and help me realize that I need to properly check my stuff before wasting your time with something I already knew. Still, hope other viewers receive help from this post. Thank you for the reply!
User is offlineProfile CardPM
+Quote Post

villalandron

RE: Count In Two Lines

1 Jul, 2009 - 08:13 PM
Post #5

D.I.C Head
**

Joined: 24 Sep, 2008
Posts: 124

QUOTE(villalandron @ 1 Jul, 2009 - 07:59 PM) *

QUOTE(computerfox @ 1 Jul, 2009 - 06:18 PM) *

QUOTE(villalandron @ 1 Jul, 2009 - 06:12 PM) *

I am having problems with this program. I need to build a program that will demonstrate a loop that will print the following output by using two loops:.
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20

Here's what I have so far:

CODE


import java.util.Scanner;

public class TwoLines
{
   public static void main (String[ ] args)
   {
        Scanner keyboard = new Scanner(System.in);
                
        for (int number = 1; number <=10; number++)
        System.out.print("\t" + number);
        
        System.out.print("\n");
        
        for (int num = 11; num <= 20; num+=1)
        System.out.print("\t" + num);    
   }//end main method
}//end class



Thank you for your help!


where's your question? unsure.gif

but just to let you know:
CODE

for (int number = 1; number <=10; number++)
System.out.print(number+" ");
        
System.out.print("\n");
        
for (int num = 11; num <= 20; num++)
System.out.print(num+" ");


hope that helps smile.gif


Honestly, I don't know why I made that question because after looking at the last post made me realize that I knew how to do that. Anyways, thank you for opening my eyes and help me realize that I need to properly check my stuff before wasting your time with something I already knew. Still, hope other viewers receive help from this post. Thank you for the reply!

Actually, this I don't know. If I wanted to make a program perform this output:

1 2
3 4
5 6
7 8
9 10

How would I do it? I've been trying but this is as close as I can get:

CODE


import java.util.Scanner;

public class TwoLines
{
   public static void main (String[ ] args)
   {
        
        Scanner keyboard = new Scanner(System.in);
                
        for (int number = 1 && int num = 1; number <=5; number++)
        System.out.println("\t" + number);
        
   }//end main method
}//end class


User is offlineProfile CardPM
+Quote Post

Fuzzyness

RE: Count In Two Lines

1 Jul, 2009 - 08:17 PM
Post #6

Comp Sci Student
Group Icon

Joined: 6 Mar, 2009
Posts: 1,149



Thanked: 173 times
Dream Kudos: 150
My Contributions
Well, read in the numbers to an arraylist/array whatever you prefer.
Make a for loop to print out each number using the index based off of a %2 == 0 basis to print a new line
CODE

for(int i = 1; i<=numbers.length; i++)
{
     System.out.print(" " + numbers[i-1]);
     if(i %2 == 0)
          System.out.println();
}


Hope this helps!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 04:43AM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month