My assignment is to using loops output this
1 2 3 4 5 6
2 3 4 5 6 7
3 4 5 6 7 8
4 5 6 7 8 9
5 6 7 8 9 10
As of now my program
public class Assigment10
{
public static void main(String[] args)
{
for(int i = 1; i < 7; i++)
{
System.out.print(i + " ");
}
for(int i = 2; i < 8; i++)
{
System.out.print(i + " ");
}
for(int i = 3; i < 9; i++)
{
System.out.print(i + " ");
}
for(int i = 4; i < 10; i++)
{
System.out.print(i + " ");
}
for(int i = 5; i < 11; i++)
{
System.out.print(i + " ");
}
}
}
Outputs 1 2 3 4 5 6 2 3 4 5 6 7 Ect, using \r \n gives me vertical positions for the numbers is there a way to get the orientation I need?
Use System.out.println();
after each loop except the last one.
public class Assigment10 {
public static void main(String[] args)
{
for (int i = 1; i < 7; i++) {
System.out.print(i + " ");
}
System.out.println();
for (int i = 2; i < 8; i++) {
System.out.print(i + " ");
}
System.out.println();
for (int i = 3; i < 9; i++) {
System.out.print(i + " ");
}
System.out.println();
for (int i = 4; i < 10; i++) {
System.out.print(i + " ");
}
System.out.println();
for (int i = 5; i < 11; i++) {
System.out.print(i + " ");
}
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments