Small issue initializing a variable and/or updating the value throughout the code

variable initialization in c++
why do we need to initialize variables in c++
assigning values to variables in java
difference between initialization and assignment in c++
c++ initialize variable with curly braces
variable declaration and initialization in c++
storing a value in a variable is called
initializing a variable in java

I had a functional version earlier that used less unique variables and just more instances of the first variable, but after adding in two more variables whose values are related to the first one, my code comes up with an error showing that I need to initialize my variable "numbList".

Ideally I'd like to simply update the value of "numbList" after each new line, which will then update the values of "numbSquare" and "numbCube". So far I haven't had much luck.

public class Assignment2BPart2 {
    public static void main(String[] args) {
        int numbList;
        int numbSquare;
        int numbCube;

        numbSquare = numbList * numbList;
        numbCube = numbSquare * numbList;

        System.out.println("The following is a table of values, showing numbers 0 - 10 and their squares and cubes.");
        System.out.printf("%s%s%s%n", "Number   ", "Square  ", "Cube");
        System.out.printf("%d \t %d \t %d%n", numbList = 0, numbSquare, numbCube);
        System.out.printf("%d \t %d \t %d%n", numbList = 1, numbSquare, numbCube);
        System.out.printf("%d \t %d \t %d%n", numbList = 2, numbSquare, numbCube);
        System.out.printf("%d \t %d \t %d%n", numbList = 3, numbSquare, numbCube);
        System.out.printf("%d \t %d \t %d%n", numbList = 4, numbSquare, numbCube);
        System.out.printf("%d \t %d \t %d%n", numbList = 5, numbSquare, numbCube);
        System.out.printf("%d \t %d \t %d%n", numbList = 6, numbSquare, numbCube);
        System.out.printf("%d \t %d \t %d%n", numbList = 7, numbSquare, numbCube);
        System.out.printf("%d \t %d \t %d%n", numbList = 8, numbSquare, numbCube);
        System.out.printf("%d \t %d \t %d%n", numbList = 9, numbSquare, numbCube);
        System.out.printf("%d \t %d \t %d%n", numbList = 10, numbSquare, numbCube);       
    }
}

The expected results would be a 3 column table with header reading

Number Square Cube

With the rest of column 1 being values 0-10, column 2 being the squares of those numbers, and column 3 being the cubes of the numbers.

So far I'm not able to run the code in this iteration.


The usual way to achieve something repetitive like this is to use a for loop:

System.out.println("The following is a table of values, showing numbers 0 - 10 and their squares and cubes.");
System.out.printf("%s%s%s%n", "Number   ", "Square  ", "Cube");

for (int num = 0; num <= 10; num++) {
    System.out.printf("%d \t %d \t %d%n", num, num * num, num * num * num);
}

Different ways to initialize a variable in C/C++, Now, whenever these marks will be updated, they will be stored at a different memory Static Initialization: Here, the variable is assigned a value in advance. Initialize Named Constants Once; Initialize Variables with Executable Code We should declare named constants with const so that they can’t be reassigned to a new value. If we have variables, they


The logic is wrong, you have to calculate the square and cube after updating the numbList, so you have to do this by using any of the loops or recursion, but i will prefer having two methods returns int value one for calculating square and other for cube

public class NewMain {

public static void main(String[] args) {
    int numbList = 0;


    System.out.println("The following is a table of values, showing numbers 0 - 10 and their squares and cubes.");

    System.out.printf("%s%s%s%n", "Number   ", "Square  ", "Cube");

    //
    System.out.printf("%d \t %d \t %d%n", numbList = 0, squareOfNumber(numbList), cubeOfNumber(numbList));
    System.out.printf("%d \t %d \t %d%n", numbList = 1, squareOfNumber(numbList), cubeOfNumber(numbList));
    System.out.printf("%d \t %d \t %d%n", numbList = 2, squareOfNumber(numbList), cubeOfNumber(numbList));
    System.out.printf("%d \t %d \t %d%n", numbList = 3, squareOfNumber(numbList), cubeOfNumber(numbList));
    System.out.printf("%d \t %d \t %d%n", numbList = 4, squareOfNumber(numbList), cubeOfNumber(numbList));
    System.out.printf("%d \t %d \t %d%n", numbList = 5, squareOfNumber(numbList), cubeOfNumber(numbList));
    System.out.printf("%d \t %d \t %d%n", numbList = 6, squareOfNumber(numbList), cubeOfNumber(numbList));
    System.out.printf("%d \t %d \t %d%n", numbList = 7, squareOfNumber(numbList), cubeOfNumber(numbList));
    System.out.printf("%d \t %d \t %d%n", numbList = 8, squareOfNumber(numbList), cubeOfNumber(numbList));
    System.out.printf("%d \t %d \t %d%n", numbList = 9, squareOfNumber(numbList), cubeOfNumber(numbList));
    System.out.printf("%d \t %d \t %d%n", numbList = 10, squareOfNumber(numbList), cubeOfNumber(numbList));
}

public static int squareOfNumber(int num) {
    return num*num;
}
public static int cubeOfNumber(int num) {
    return num*num*num;
  }
}

for loop you can apply the same logic above

for(int i=0; i<=10; i++) {
        System.out.printf("%d \t %d \t %d%n", i, i*i, i*i*i);
    }

You can also use Math.pow()

nt intResult = (int) Math.pow(2, 3);

The method raises 2 to the power of 3 and returns the result

Variables, We can also declare multiple variables in one line: languages, like Scala or Erlang that forbid changing variable values. In Even if we're writing a small script, it may have a long life ahead. Modern JavaScript minifiers and browsers optimize code well enough, so it won't create performance issues. C51: INITIALIZING AN ABSOLUTELY LOCATED VARIABLE; FORUM THREADS. The following Discussion Forum threads may provide information related to this topic. Issues initializing variable at a fixed address; _at_; how to location the start of a array at the specify address of RAM? Absolute location of constant tables in code space


The solution you are looking for is how to make the code and variables reusable. One way to do this is with functions, though you may not be up to learning about this yet. You would then use a for loop to input then numbers 1 to 10 in to your function to obtain the desired output.

 public static int NumberSquared(int number)
 {
    return number*number;
 }

 public static int NumberCubed(int number)
 {
    return number*number*number;
 }

 public static void main(String[] args) 
 {

    for(int i=0; i <= 10; i++)
    {
        System.out.println("Number " + i + " Square: " + NumberSquared(i) + " Cube: " + NumberCubed(i));
    }
 }

Programming - Variables, A variable is a symbolic name for (or reference to) information. This means the variable "stands in" for any possible values. Good programs are "Chopped" into small self contained sections (called When a program begins, variables " come to life" when the program reaches the line of code where they are "declared ". -Version 1 checks for uninitialized variables. See yesterday’s blog, Use Strict Mode for PowerShell to Help You Write Good Code, for a discussion of the -Version 2 checks. Correcting the problem of the uninitialized variable requires declaring the variable and assigning a value to it. This technique is shown here. InitializedVariable.ps1


The basic issue is the statement where you calculate the square and cube. At that instant, the number who’s square/cube value you wish to calculate hasn’t been initialised.

For now you could multiply directly in the Sys.Outs to compute the squares and cubes individually. Once you gather what loops and recursions are, the lines of code will be significantly reduced.

4. Methods Use Instance Variables: How Objects Behave, Selection from Head First Java, 2nd Edition [Book] In other words, methods use instance variable values. If you declare a method to return a value, you must return a value of the When you have more design and coding savvy in Java, you will probably do things a little differently, but Only setters should update these. Initializing the variable value. It is important to give your variables an initial value. The initial value is the value the variable will hold each time the program starts. For our counter program, we will give each variable the value 0 (zero) at the start of the program. let PlayerAWins = 0 let PlayerBWins = 0 let PlayersTie = 0 Updating the


Storing the information you need — Variables, Throughout this article, you'll be asked to type in lines of code to test your A variable is a container for a value, like a number we might use in a variables that works somewhat differently to var , fixing its issues in Once a variable has been initialized with a value, you can change (or update) that value� Variable naming is one of the most important and complex skills in programming. A quick glance at variable names can reveal which code was written by a beginner versus an experienced developer. In a real project, most of the time is spent modifying and extending an existing code base rather than writing something completely separate from scratch.


VariableDeclaration, Declaring a variable means defining its type, and optionally, setting an initial Variables will roll over when the value stored exceeds the space assigned to store it. like var or value, on the other hand, do little to make your code readable. The purpose of the code is simply to be able to open a DialogInput with a slider initialized to a piece of data read from a file. If desired, manipulate the slider to a new value and return that value along with the date. If my current approach is not a good one, I'm open to better ideas.


Advances in Software Engineering: International Conference on , 3.2 Implementation and Its Issues The main architecture of our system that was provided in the previous section was a little coarse-grained and the local variables of P0 via GDB and sets them in P0u by running an initialize function on P0u. Some safe update points are determined in the code at the compile-time [ 14]. The introduction say: "Initialize the three variables a, b, and c with 5, 10, and "I am a" respectively so that they will not be undefined." And the test suit say: "a should be defined and have a value of 6; b should be defined and have a value of 15; c should not contain undefined and should have a value of "I am a String! " it should said: