I have a table that looks like this.
1234
5678
9101112
I need to use this code
public class Lab8
{
public static void main(String argv[])
{
int ar[][] = new int[3][4];
int n = 1;
for (int i=0; i < ar.length; i++) {
for (int j=0; j< ar[i].length; j++) {
ar[i][j] = n;
n++;
}
}
// print out the elements of the array
// left to right, top to bottom
for (int i=0; i < ar.length; i++) {
for (int j=0; j < ar[i].length; j++) {
System.out.print(ar[i][j] + " ");
}
}
System.out.println();
// your code goes here!
}
}
By using a two dimensional arrays to store the table. Then use two indexes to store the values so that I can print them out like so.
== OUTPUT ================================================= 1 2 3 4 5 6 7 8 9 10 11 12 4 3 2 1 8 7 6 5 12 11 10 9 9 10 11 12 5 6 7 8 1 2 3 4 12 11 10 9 8 7 6 5 4 3 2 1 1 5 9 2 6 10 3 7 11 4 8 12 9 5 1 10 6 2 11 7 3 12 8 4 4 8 12 3 7 11 2 6 10 1 5 9 12 8 4 11 7 3 10 6 2 9 5 1
Program
public class Lab8 {
public static void main(String[] args) {
int ar[][] = new
int[3][4];
int n = 1;
for (int i=0; i <
ar.length; i++) {
for (int j=0; j< ar[i].length; j++) {
ar[i][j] = n;
n++;
}
}
// print out the
elements of the array
// left to right, top to
bottom
System.out.println("\n==
OUTPUT =================================================");
for (int i=0; i <
ar.length; i++) {
for (int j=0; j < ar[i].length; j++) {
System.out.print(ar[i][j] + " ");
}
}
System.out.println();
for (int i=0; i <
ar.length; i++) {
for(int j = ar[i].length-1; j >=0; j--)
{
System.out.print(ar[i][j] + " ");
}
}
System.out.println();
for (int i=ar.length-1;
i >=0; i--) {
for (int j=0; j < ar[i].length; j++) {
System.out.print(ar[i][j] + " ");
}
}
System.out.println();
for (int i=ar.length-1;
i >=0; i--) {
for(int j = ar[i].length-1; j >=0; j--)
{
System.out.print(ar[i][j] + " ");
}
}
System.out.println();
for (int i=0; i
<=ar.length; i++) {
for (int j=0; j < ar.length; j++) {
System.out.print(ar[j][i] + " ");
}
}
System.out.println();
for (int j=0; j <
ar.length+1; j++) {
for (int i=ar.length-1; i
>=0; i--) {
System.out.print(ar[i][j] + " ");
}
}
System.out.println();
for(int j = ar.length; j
>=0; j--) {
for (int i=0; i <ar.length;
i++) {
System.out.print(ar[i][j] + " ");
}}
System.out.println();
for(int j = ar.length; j
>=0; j--) {
for (int i=ar.length-1; i
>=0; i--) {
System.out.print(ar[i][j] + " ");
}}
}
}
Output
== OUTPUT
=================================================
1 2 3 4 5 6 7 8 9 10 11 12
4 3 2 1 8 7 6 5 12 11 10 9
9 10 11 12 5 6 7 8 1 2 3 4
12 11 10 9 8 7 6 5 4 3 2 1
1 5 9 2 6 10 3 7 11 4 8 12
9 5 1 10 6 2 11 7 3 12 8 4
4 8 12 3 7 11 2 6 10 1 5 9
12 8 4 11 7 3 10 6 2 9 5 1
I have a table that looks like this. 1234 5678 9101112 I need to use this...
1 4 7 10 2 5 8 11 3 6 9 12 I want to print this matrix in c language. How did this formula come out? ļ¼3 * j + i + 1); #include <stdio.h> int main() { int y[3][4]; int i, j; for (i = 0; i < 3; i++) { for (j = 0; j < 4; j++) printf("%d ", 3 * j + i + 1); printf("\n"); } return 0; }
For questions 10-12, refer to the following iterative code computes values for the table t. 1 public int [] tIterative (int [C A)1 2 3 4 int n - A.length; int [] t = new int [n]; int j; for (inti-0; i 0) while (j > 0 && A[j] [1] A[i] [O]) 12 13 14 15 16 t[i]Math.max( t[i-1] , A[i][i] - A[i] [o] + t[j] ); return t; 10. Does the code for tIterative use dynamic programming? 11. What...
I am writing a program to play the game "Game of Life". I am hoping someone can help me edit my sad program so that it will print the first board as well as the next generation. The first board is working just fine. It is the next generation that is not working and i'm not sure what I am doing wrong. Thanks in advance. public class Life { public char FirstBoard[][]; public Life() { FirstBoard =...
Java code for percolation, code compiles correctly but when it takes values for Input10.txt , the code is suppose to comeback that the system percolates but instead it comes back with the exception. Photos below show the exception. I belive there may be an issue with my logic in the for loop for when to throw the exception. also, i have put the values of Input10.txt at the bottom to try and use to see the exception. The exception i...
print(" |",end=' ')
for i in range(1,10):
print(i,end=' ')
print()
for i in range(0,11):
print('-',end=' ')
print()
for i in range(1,10):
for j in range(0,11):
if j==0:
print(i,end=' ')
elif j==1:
print('|',end=' ')
elif i==9 and j==10:
print(i*(j-1),end=' ')
elif i>=4 and j>=4:
print('*',end=' ')
else:
print(i*(j-1),end=' ')
print()
This code is not working I need help
1 2 3 4 5 6 7 8 9 --- --- -------------------- -------------------- 5 10 15 X 6 12 18 X 7 8...
Can someone help me with this please: #include <iostream> #include <cstdlib> #include <string> #include <cstring> using namespace std; #define ARSIZ 150000 int debug=0; void dump(int ar[], int len) { for(int i=0; i<len; i++) { cout<<" DUMP: data = : "<< ar[i] << endl; } } void sort(int *ar, int length) { if(length == 1 || length == 0) return; cout << "BREAKING DOWN: " << endl; //for(int i=0; i<length; i++) // cout << " DUMP: DATA = : " <<...
I need to create a C++ program to simulate a Round Robin Tournament. For example: if a user enters 4, a 4 team tournament would output: 1 2 3 4 2 1 4 3 3 4 1 2 4 3 2 1 My goal is to create this program using a two dimentional array, however I am unsure how to go about doing initializing everything. How do I write a constructor for this? The following is the class declaration I...
QUESTION 9 What will be the output of following code snippet? int a[3] = {1, 2, 3}; int *p = a; int **r = &p; printf("%p %p", *r, a); A. Different memory addresses printed B. 1 2 C. Same memory address printed twice D. 1 1 2 points QUESTION 10 What will be the output of following code snippet? int arr[4] = {1, 2, 3, 4}; int *p; p = arr + 3; *p = 5; printf("%d\n", arr[3]); A....
Please help in C: with the following code, i am getting a random 127 printed in front of my reverse display of the array. The file i am pulling (data.txt) is: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 when the reverse prints, it prints: 127 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 not sure why...please...
Help !! I need help with Depth-First Search using an
undirected graph.
Write a program, IN JAVA, to implement the
depth-first search algorithm using the pseudocode given.
Write a driver program, which reads input file mediumG.txt as an
undirected graph and runs
the depth-first search algorithm to find paths to all the other
vertices considering 0 as the
source. This driver program should display the paths in the
following manner:
0 to āvā: list of all the vertices traversed to...