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

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




LOOPS

 
Reply to this topicStart new topic

LOOPS

mezig101
17 Aug, 2007 - 02:20 PM
Post #1

D.I.C Head
**

Joined: 1 Aug, 2007
Posts: 54


My Contributions
Hi, Im working on a program using loops but I can't seem to get it right..I need help.

Im suppose to make a multiplication table using the for loops but it's not working..I've done\
\

[ import java.util.Scanner;
class Pictures
{
void printTable(int rows, int col)
{
for(int row = 1; row <= 1; row++)
{
for(int column = 1; col <= 1; col++)
System.out.print("");
System.out.println();
}

for(int row = 2; row <=5; row++)
{
for(int column = 2; col <= 7; col++)
System.out.print(row);
System.out.print(col);
System.out.println();
}
}



}


public class PictureTester
{
public static void main (String[ ] args)
{
Pictures pic = new Pictures ( );
Scanner in = new Scanner(System.in);
String get;
pic.printTable (4, 6);
get = in.nextLine ( ); // freezes the output screen to see the picture
pic.printTable (11,12);
get = in.nextLine ( );

}
}

]


but it's wrong..the outcome needs to be something like

Sample run output for printTable (4, 6):

1 2 3 4 5 6

1 1 2 3 4 5 6
2 2 4 6 8 10 12
3 3 6 9 12 15 18
4 4 8 12 16 20 24


but didn't work sad.gif

plz tell me what i need to do and explain loops to me


User is offlineProfile CardPM
+Quote Post

mezig101
RE: LOOPS
17 Aug, 2007 - 02:57 PM
Post #2

D.I.C Head
**

Joined: 1 Aug, 2007
Posts: 54


My Contributions
QUOTE(mezig101 @ 17 Aug, 2007 - 03:20 PM) *

Hi, Im working on a program using loops but I can't seem to get it right..I need help.

Im suppose to make a multiplication table using the for loops but it's not working..I've done\
\

[ import java.util.Scanner;
class Pictures
{
void printTable(int rows, int col)
{
for(int row = 1; row <= 1; row++)
{
for(int column = 1; col <= 1; col++)
System.out.print("");
System.out.println();
}

for(int row = 2; row <=5; row++)
{
for(int column = 2; col <= 7; col++)
System.out.print(row);
System.out.print(col);
System.out.println();
}
}



}


public class PictureTester
{
public static void main (String[ ] args)
{
Pictures pic = new Pictures ( );
Scanner in = new Scanner(System.in);
String get;
pic.printTable (4, 6);
get = in.nextLine ( ); // freezes the output screen to see the picture
pic.printTable (11,12);
get = in.nextLine ( );

}
}

]


but it's wrong..the outcome needs to be something like

Sample run output for printTable (4, 6):

1 2 3 4 5 6

1 1 2 3 4 5 6
2 2 4 6 8 10 12
3 3 6 9 12 15 18
4 4 8 12 16 20 24


but didn't work sad.gif

plz tell me what i need to do and explain loops to me



ok sooo i figured as far as getting all the numbers but idk how to start the new line


import java.util.Scanner;
class Pictures
{
void printTable(int rows, int col)
{
for(int row = 1; row <= 6; row++)
{
for(int column = 1; column <= 7; column++)
{
System.out.print(row*column);
}

}
}
}


public class PictureTester
{
public static void main (String[ ] args)
{
Pictures pic = new Pictures ( );
Scanner in = new Scanner(System.in);
String get;
pic.printTable (4, 6);
get = in.nextLine ( ); // freezes the output screen to see the picture
pic.printTable (11,12);
get = in.nextLine ( );

}
}


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 07:54PM

Be Social

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

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month