Question

In: Computer Science

How would I get this started: Code a logic program that uses a for loop to...

How would I get this started:

Code a logic program that uses a for loop to call your method 5 times successively on the values 1 through 5. (i.e. it would display the val and it’s square…)

Solutions

Expert Solution

Java code for the given requirement:

public class Demo{

   public static void main(String arg[]){

       //Using for loop to call the method exactly five times for the values of 1 through 5

          for(int i=1; i<=5; i++) {

                 //Calling the display square method

                 displaySquare(i);

          }

     

   }

   private static void displaySquare(int i) {

              //TODO Auto-generated method stub

              //displaying the value and its square

              System.out.println(i+" and it's square is "+i*i);

       }

}

Output:


Related Solutions

How would I get this java code to work and with a main class that would...
How would I get this java code to work and with a main class that would demo the rat class? class rat { private String name; private String specialAbility; private int TotalHealth; private int shieldedHealth; private int cooldown; public rat() { } public rat(String n,String SA,int TH,int SH,int cd) { name=n; specialAbility=SA; TotalHealth=TH; shieldedHealth=SH; cooldown=cd; } public void setname(String n) { name=n; } public String getname() { return name; } public void setability(String SA) { specialAbility=SA; } public String getability()...
(This is for java) I need to rewrite this code that uses a while loop. public...
(This is for java) I need to rewrite this code that uses a while loop. public class Practice6 {      public static void main (String [] args) {         int sum = 2, i=2;        do { sum *= 6;    i++;    } while (i < 20); System.out.println("Total is: " + sum); }
How would you represent a for loop in First Order Logic terms? Is it possible to...
How would you represent a for loop in First Order Logic terms? Is it possible to implement a for loop using First Order Logic terms? What about Propositional Logic?
I have to code the assignment below. I cannot get the program to work and I...
I have to code the assignment below. I cannot get the program to work and I am not sure what i am missing to get the code to work past the input of the two numbers from the user. My code is listed under the assignment details. Please help! Write a Java program that displays the prime numbers between A and B. Inputs: Prompt the user for the values A and B, which should be integers with B greater than...
Write an assembly program (Data and Code) that uses loop to read 10 numbers and output...
Write an assembly program (Data and Code) that uses loop to read 10 numbers and output the largest of those numbers, you can assume any length for those numbers. 80x86 assembly language
How would I write this driver program in C++?? We just started learning C++ and I...
How would I write this driver program in C++?? We just started learning C++ and I still don't understand how to use classes or randomly generate numbers, and I'm struggling to complete this assignment. The premise of the whole assignment is to randomly generate dates within a range and format the dates in 3 different ways. Calendar.cpp Create a driver program with a main function. Use symbolic constants or "const" declarations here, also. In particular, define local constant SIZE to...
Based on Chandler’s logic of managerial enterprise,I would like to get the explanation and brief example...
Based on Chandler’s logic of managerial enterprise,I would like to get the explanation and brief example of Managerial Enterprise: Large industrial concerns operating and investment decisions are made by a hierarchy of salaried managers managers governed by a board of directors
I am trying to get this code to work but I am having difficulties, would like...
I am trying to get this code to work but I am having difficulties, would like to see if some one can solve it. I tried to start it but im not sure what im doing wrong. please explain if possible package edu.hfcc; /* * Create Java application that will create Fruit class and Bread class * * Fruit class will have 3 data fields name and quantity which you can change. * The third data field price should always...
Write a program that uses loops (both the for-loop and the while loop). This assignment also...
Write a program that uses loops (both the for-loop and the while loop). This assignment also uses a simple array as a collection data structure (give you some exposure to the concept of data structure and the knowledge of array in Java). In this assignment, you are asked to construct an application that will store and retrieve data. The sequence of data retrieval relative to the input is Last In First Out (LIFO). Obviously, the best data structure that can...
Write a program that uses a for loop to print One of the months of the...
Write a program that uses a for loop to print One of the months of the year is January One of the months of the year is February ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT