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);```
}
Related
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 4 months ago.
Improve this question
I'm learning java now, sorry if you didn't get it.
Here is the "money transfer" method, it works with constructor in other class.
The code does not end by itself, it constantly returns.
I need to save these parameters (username, transfer amount) and execute this later.
public static String moneyTransfer() {
System.out.println("Enter the name to whom you want to transfer funds");
String nametransfer = scanner.nextLine();
String nametransf = scanner.nextLine();
System.out.println("Enter the amount to transfer to the user " + nametransfer);
int transfermoney = scanner.nextInt();
Moneytransfer moneytr = new Moneytransfer(nametransf, transfermoney);
int resulttransfer = balance-transfermoney;
System.out.println("You transferred "+transfermoney+" to user: "+nametransf);
System.out.println("balance: "+resulttransfer);
return startPanel();
}
idk(
You can store them with a List in package java.util.
As you are new to programming, you might not understand what I am talking about. Just keep learning and you will realise.
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 am trying to convert the following Java code into swift, but I do not know about this data structure new (int start, int end)[input. length], any guidance would be appraciated.
public override void collection_entries(int[] input)
{
var ranges = new (int start, int end)[input.length];
}
In swift, you should use a Range().
let start = 0
let end = 6
var ranges = Range(start...end)[input.count]
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 6 years ago.
Improve this question
I have
for( int x = 0; x < rp.studentRecords.length; x++){
System.out.println("Student name: " +rp.studentRecords[x].getName());
System.out.println("Major: "+ rp.studentRecords[x].getClass().getName());
System.out.println("Age: "+ rp.studentRecords[x].getName());
System.out.println("Year " +rp.studentRecords[x].getYear());
System.out.println("Credits Earned: "+ rp.studentRecords[x].getCredits());
System.out.println("Remaining Credits: "+ rp.studentRecords[x].getRemainingCredits());
System.out.println("-------");
}
and I need to condense those System.out.println()s into a single one.
What you could try is to use String.format like
String output = String.format ("Name: %s\nMajor: %s\nAge: %s",
rp.studentRecords[x].getName(),
rp.studentRecords[x].getClass().getName(),
rp.studentRecords[x].getAge());
// then print it out
System.out.println (output);
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]);
}
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!!!