Solved

# Java - Loop

Posted on 2008-11-18
Medium Priority
3,358 Views
I add this part to the code.
int i;
for (i = 1; i <=10; i++)
but it is not doing what I need.
I just repeats the answer 10 times.

How do you determine the numeric grade for one single letter grade, it repeatedly calculates and displays numeric grades for a sequence of exactly 10 grades?

Any help would greatly be appreciated.

package charatmethod;
import java.util.Scanner;

public class CharAtMethod
{

public static void main(String[] args)
{
Scanner in = new Scanner(System.in);

String input = in.nextLine();

int i;
for (i = 1; i <=10; i++)
}

}
************************************
package charatmethod;
{
{
}
{
{
case 'B': grade = 3.0; break;
case 'C': grade = 2.0; break;
case 'D': grade = 1.0; break;

}

for (int i = 0; i < letterGrade.length(); i++)
{
}

}
}
0
Question by:ca1358

LVL 12

Expert Comment

ID: 22990735
I'm not totally sure what you're trying to do.  If you take out the for loop in your main method, you will ask for one letter grade and output the related numeric grade.  If you want a loop, it would have to encompass the part where you ask for a grade.  You'd probably want to go until nothing is entered, to indicate it's done (versus a for loop).
0

Author Comment

ID: 22990767
I am not sure what it asking.

It states
Alter the main class of the project so that, instead of just determining the numeric grade for one single letter grade, it repeatedly calculates and displays numeric grades for a sequence of exactly 10 grades.

You should add a loop to the main method that will ensure that the process of "retrieve letter grade, then calculate and display the numeric grade, will be repeated 10 times.

Of course it gives no explanation of how to do this.
0

LVL 15

Expert Comment

ID: 22990783
do you actually want something like
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String input;

int i;
for (i = 1; i <=10; i++)
{
input = in.nextLine();
}
}
0

LVL 60

Accepted Solution

Kevin Cross earned 2000 total points
ID: 22990821
Think you want something more like this so that you keep prompting for letter grade and displaying for 10 times and then stops.
public class CharAtMethod {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);

for (int i = 1; i <= 10; i++) {
}
}
}
0

LVL 60

Expert Comment

ID: 22990838
That is what I get for not refreshing, what quincydude is pretty much what I was trying to show you.  You just needed to move the code for input and conversion from letter grade to inside the for loop.

This is just hte basics of the solution and should get you started.  You will have to ensure that you get valid input each time if they want 10 good executions.  Other interpretation/implementation could be to allow entry of 10 grades in a row and then calculate and display all ten at once.  Again that is all based on the above code as a start so good luck.

Regards,
Kevin
0

Author Closing Comment

ID: 31518089
Thanks!!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
###### Suggested Courses
Course of the Month13 days, 15 hours left to enroll