Hi, I have been given the following program to create but am unsure of what conditions to put in the for loop.:
Write a Java program which uses a for loop to
- print out the following multiple number pattern for:
- rows beginning with numbers: 4, 5, 6, 7;
- print in FORMAT as shown below:
4 8 12 16
5 10 15 20
6 12 18 24
7 14 21 28
I am able to get the multiples of 4 by doing this:
public class NumberPattern
{
public static void main(String[] args)
{
int number=0, count=0;
for(number=4; count<=4; number+=4)
{
System.out.print(number+"\t\t");
count++;
}//for
}//main
}//class
But is there a single condition that will complete the above process for each of the four numbers (4,5,6 & 7)??
5 replies to this topic
#1
Posted 14 February 2012 - 11:51 AM
|
|
|
#2
Posted 14 February 2012 - 12:11 PM
public class NumberPattern
{
public static void main(String[] args)
{
int number=0, count=0;
for (number=4;number<=7;number+=1)
{
}//main
}//class
{
public static void main(String[] args)
{
int number=0, count=0;
for (number=4;number<=7;number+=1)
{
for(count=1;count<=4;count+=1)
{
System.out.print(number*count+"\t\t");
}//for
System.out.print("\n");
}//main
}//class
#3
Posted 14 February 2012 - 12:18 PM
Thank-You so much!
I'm just beginning to learn Java but I can understand what you've done there!
:)
I'm just beginning to learn Java but I can understand what you've done there!
:)
#4
Posted 14 February 2012 - 10:10 PM
You r Welcome :)
#5
Posted 14 February 2012 - 11:44 PM
public class TableDemo {
public static void main(String[] args) {
int num1=0,num2=0;
for(num1=4;num1<=7;num1++) {
for(num2=1;num2<=10;num2++)
System.out.print(num1*num2 + " ");
System.out.println();
}
}
and dnt forget to say me thank u......ok
public static void main(String[] args) {
int num1=0,num2=0;
for(num1=4;num1<=7;num1++) {
for(num2=1;num2<=10;num2++)
System.out.print(num1*num2 + " ");
System.out.println();
}
}
and dnt forget to say me thank u......ok
#6
Posted 15 February 2012 - 09:28 AM
Thank You Also! :thumbup1:
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









