Computer Science, asked by chaurasiyalalit58, 5 months ago

write a method that receives a number and returns the cube of the number. कुत्ते सही jawab de​

Answers

Answered by Anonymous
10

Answer:

As you have already discovered, simple numeric input in Java is not as simple as it is in BASIC or C. (Or am I misunderstanding the question to assume that you want to input a number, then return the cube of the number?

In BASIC, I could simply say: INPUT number

In JAVA, I need to use several statements to do the same thing. Below, I describe statements I used in a program I wrote while learning JAVA:

import before the public statements allows you to use predefined utility statements in the methods themselves:

import java.util.Scanner;

a new Scanner device statement allows you to input entire numbers:

Scanner inputDevice = new Scanner(System.in);

after your program has displayed a message describing what you want to input, use these two statements to input the next integer (assuming you are using integers), then to discard the rest of the line:

number = inputDevice.nextInt();

(there are similar options for ‘next’ other types of numbers/strings.)

inputDevice.nextLine();

(this tells system to ignore the rest of the line including the next line character.)

I have used variations of the statements above in one of my homework problems for cctech. edu’s JAVA course.

Finally, you want to cube the number. This is the same as raising the number to the third power.

I have not tested this, but I assume this is as simple as

cube = number ^ 3;

I assume that you know the rest of what you need in order to create your program.

Explanation:

and please don't  use these rubbish words here.....

Similar questions