Jump to content

FOR Loop - Please Help

- - - - -

  • Please log in to reply
5 replies to this topic

#1
emz540

emz540

    Newbie

  • Members
  • Pip
  • 3 posts
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)??

#2
Anirban Mukherjee

Anirban Mukherjee

    Newbie

  • Members
  • Pip
  • 2 posts
public class NumberPattern
{
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
emz540

emz540

    Newbie

  • Members
  • Pip
  • 3 posts
Thank-You so much!
I'm just beginning to learn Java but I can understand what you've done there!
:)

#4
Anirban Mukherjee

Anirban Mukherjee

    Newbie

  • Members
  • Pip
  • 2 posts
You r Welcome :)

#5
Ritesh Srivastav

Ritesh Srivastav

    Newbie

  • Members
  • Pip
  • 5 posts
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

#6
emz540

emz540

    Newbie

  • Members
  • Pip
  • 3 posts
Thank You Also! :thumbup1:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users