Considering the following method: [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
public static int secret(int value) {
int prod = 1;
for(int i =1; i <= 3; i++) {
prod = prod * value;
}
return prod;
}
What would be the output of:
System.out.println("First secret call: " + secret(5));
System.out.println("Second secret call: " + (2 * secret(6)));
and what does the method secret do

The output would be 125 and then 432. The method, "secret", cubes the number passed into it.

everything fits in a very small screenshot in two windows... try it, you will see it is fun, like playing lego but with more magic!!!

Related

How do I put this in a for-loop [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I would like to put the following to a for loop. How do I do this since we haven't studied arrays yet. My instructor would like me to put the quarters 1-4 to a for loop.
quarter = 1;
interest = principal * quarterlyRate; // item 5
finalAmount = principal + interest;
System.out.printf("%6s%8d%16.2f%30.2f%n", year, quarter, interest, finalAmount);```
Maybe this is what you want:
# looping here
for (int i=0; i<4; i++) {
interest = principal * quarterlyRate; // item 5
finalAmount = principal + interest;
System.out.printf("%6s%8d%16.2f%30.2f%n", year, i, interest, finalAmount);```
}

Writing arithmetic code in Java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have the below one line of code:
variableDoubleValue = ((10*variableDoubleA) + (6.25*variableDoubleB) – (5*variableByteC) + 5);
How can I write it in a Java understandable code?
From what I infer from your question, you want a Java-language based variable declaration and assignment.
Well, if this is the case, then the result will be :-
//public class MathemathicalExpression{
// public static void main(String[] args){
// Double A=some_value,B=some_value,Value=0; considering A,B and Value to be of type Double
// Byte C=some_value; considering C to be of type Byte.
Value = 10 * A + 6.25 * B - 5 * C + 5;
// }
//}

how do I change a for loop to for each loop [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
CODE:
for (int i =0; i<=10; i++) {
System.out.println(movieasArrayList.get(i).getID() + " " + movieasArrayList.get(i).getAction());
}
QUESTION:
Change this for-loop to a for-each loop to perform the same task for all Movies (not just first 11).
Any help will be appreciated!!
The for-each loop structure in java goes as follows:
// works with collections and arrays, everything
// that has an iterator
Collection<Object> c = new Collection<Object>();
for (Object i : c) {
// do code
}
For you, this would look like this:
// I don't know what your movieArrayList contains
for (Movie i : movieArrayList) {
System.out.println(i.getId() + " " + i.getAction());
}
Hope this helps!

android java string operation [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
What is the equivalent Java for this PHP code?
//print string plus/with variable
$mystring = "this is string " .$string
//print sum one + two
$count = $one + $two
//print sum one*two
$count = $one * $two
It should be like :
String mystring= "this is string " + string; // here `string` is aloso String object
/*
* if count ,one and two all of them are int
*/
int count = one + two;
int count = one * two;
But i would suggest to learn basics of java before starting android. As you know php it will not take long to learn java syntax.

how to retrieve value in array from mysql table in java? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i want to store string value in array or in in separate variable using java please short out my problem
Thanks
String a1,a2,a3;
while (resultSet.next()) {
isFound=true;
jLabel2.setText("hello");
String s1=resultSet.getString("Court_Num");
System.out.println(s1);
output s1=: 101
102
103
Desired out put: a1=101
a2=102
a3=103
Your question is confusing I think for 1st record you want a1=101 for 2nd a2=102 etc
int i=1;
while (resultSet.next()) {
if(i==1)
{String s1=resultSet.getString("Court_Num");
System.out.println(a1+"="+s1);}
if(i==2)
{String s1=resultSet.getString("Court_Num");
System.out.println(a2+"="+s1);}
if(i==3)
{String s1=resultSet.getString("Court_Num");
System.out.println(a3+"="+s1);}
i++
The title mentioned using an array. That would look something like this:
String[] a = new String[3];
for(int i=0; resultSet.next(); i++) {
a[i] = resultSet.getString("Court_Num");
System.out.println("a" + i + "=" + a[i]);
}

Categories

Resources