Java use for loop (nested for loop) if/else possible
on blue J.
(row *col)%2 for 0's and 1's.
Please find the answer below:
I have created a separate method which prints design according to the argument passed.
I have mentioned all the details in the comment.
Please change class name according to your requirement.
import java.util.Scanner; public class Table { public static int SIZE = 7; //method to print different design as per requirement public static void print_design(int d,int n){ switch (d){ case 1 : System.out.print(" "); break; case 2: System.out.print("------- "); break; case 3: System.out.print(" |"); break; case 4: System.out.print(" |"); break; case 5: System.out.print(" "+n+" |"); break; case 6: System.out.print(" -------|"); break; case 7: System.out.print("-------|"); break; case 8: System.out.print("| |"); break; case 9: System.out.print(" |"); break; case 10: System.out.print("| "+n+" |"); break; case 11: System.out.print("|-------|"); break; } } //print the last line of each row public static void print_row_label(int row){ for(int i=0;i<=SIZE;i++){ //if it's first row if(i==0 && row==0){ print_design(6,-1); } //for each row except 0th one else if(i==0 && row==1){ print_design(11,-1); } //for all other values else{ print_design(7,-1); } } } //method to print coloumn header public static void print_coloum_header(){ for(int i=0;i<=SIZE;i++){ if(i==0){ print_design(1,-1); } else{ print_design(2,-1); } } System.out.println(); for(int i=0;i<=SIZE;i++){ if(i==0){ print_design(3,-1); } else{ print_design(4,-1); } } System.out.println(); for(int i=0;i<=SIZE;i++){ if(i==0){ print_design(3,-1); } else{ print_design(5,i); } } System.out.println(); for(int i=0;i<=SIZE;i++){ if(i==0){ print_design(3,-1); } else{ print_design(4,-1); } } System.out.println(); print_row_label(0); System.out.println(); } //method to print each individual row public static void print_row(int row){ int i; for(i=0;i<=SIZE;i++){ if(i==0) print_design(8,-1); else print_design(9,-1); } System.out.println(); for(i=0;i<=SIZE;i++){ if(i==0) print_design(10,row); else print_design(5,(row*i)%2); } System.out.println(); print_row_label(1); System.out.println(); } public static void main(String[] args) { int i,j; //to get the size from user //if you don't want it comment next 5 lines int n; Scanner sc = new Scanner(System.in); System.out.print("Enter the SIZE: "); n = sc.nextInt(); Table.SIZE = n; //code to print the table //print coloum headers print_coloum_header(); //print each row after that for(i=1;i<=SIZE;i++){ print_row(i); } } }
Output:
Java use for loop (nested for loop) if/else possible on blue J. (row *col)%2 for 0's and 1's.
Using Python, Can someone please assist in the following: These are the hints: Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to display a warning if the number is less than 2 or greater than 10 and prompt the user to enter the data again until they enter a valid number Put a...
Row and columns sum Create a java program that: Input: Receive as input in command line the sizes m and n of a two dimensional array Receive as input in command line the minValue and maxValue between which the random numbers will be generated for your two dimensional array Generate: Generate a two-dimensional with numbers between minValue and maxValue (inclusive) with the given size (m x n) Compute: Compute the sum for each row and store the results in a...
Need some help I am not understanding this programming class at all. We are using Microsoft visual studio with python in console mode to complete these labs. Double-click to hide white space CIS115 Week 4 Lab Overview Title of Lab: Multiplication Table in Python Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to...
java Write an application that input a number from the user and checks if all digits are prime numbers using method prime. The number entered can be of any size. If all digits are prime your program should stop. Use do/while for reading the input and any loop format to test if the number is prime. When checking the prime numbers don’t use an if to check numbers from 1 – 9; you need to find an algorithm to check...
PLEASE COMPLETE IN C++ LANGUAGE Location row : int = -1 col : int = -1 setLocation(row : int, col : int) getRow(): int getColl): int isEmpty(): bool Details Write all the code necessary to implement the Location class as shown in the UML Class Diagram to the right. Do this in a project named snake (we'll continue adding files to this project as the term progresses). Your class definition and implementation should be in separate files. When complete, you...
need help with java In this program you will use a Stack to implement backtracking to solve Sudoku puzzles. Part I. Implement the stack class. Created a generic, singly-linked implementation of a Stack with a topPtr as the only instance variable. Implement the following methods only: public MyStack() //the constructor should simply set the topPtr to null public void push(E e) public E pop() Test your class thoroughly before using it within the soduku program Part II. Create...
hello. i need help with number 2 ONLY 1. Use if statements to write a Java program that inputs a single letter and prints out the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way 2=ABC 3 = DEF 4 GHI 5 JKL 6 - MNO 7 - PRS 8 - TUV 9-WXY No digit corresponds to either Qor Z. For these 2 letters your program should print a message indicating that they...
IN PYTHON Print out a table of powers. Use a for loop that goes from 101 to 112 inclusive. Print out r, r squared, r cubed, square root of r, and cube root of r. Use two decimal places for the roots, and zero decimal places for the squares and cubes, and 2 decimal places for the averages. Use commas in numbers 1000 and above. After the loop, print out the average of the r squared and r cubed. Use...
NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not receive any credit, so be sure that your code interprets correctly...
write a java program that does the following Part one Use a For loop to compute the sum of all the odd numbers from 1 through 99. Your result should be labeled, and the value should be 2500. Print your name 7 times using a While loop. String dogNames[ ] = {"Sam","Buster","Fido","Patches","Gromit","Flicka"}; Using the array defined here, print the values of the array vertically and horizontally using one For-Each loop. Reverse the logic (Nested loops: Indent text) so that the...