Computer Science, asked by dastitli700, 2 months ago

write the programs in java using Given value:
3. print the cube and twice of 20.​

Answers

Answered by anindyaadhikari13
4

Solution:

Program to print cube and twice of 20 is given below –

public class Program {

public static void main(String[] args) {

int a=20;

int twice=a*2;

int cube=a*a*a;

System.out.println("Cube of 20: "+cube);

System.out.println("Twice of 20: "+twice);

}

}

Logic:

  • Store 20 in a variable - a.
  • Multiply a by 2 and store the result in variable - twice.
  • Store the cube of a in another variable - cube.
  • Display the values of the variables - twice and cube.

See the attachment for output.

Attachments:
Answered by BrainlyProgrammer
2

Answer:

class Display {

public static void main (String ar []){

int a=3,b=20;

System.out.println("Cube of 3:"+(Math.pow(a,3)));

System.out.println("Twice of 20:"+(b*2));

}

}

  • You can also use (a*a*a) instead of Math.pow(a,3)
  • pow() is for number raisedto power other number
Similar questions