im having problems with my java homework. I really need help. I need to use a loop make sure what the user input for their grade is vaild the grade has to be between 150 and 0. So can somebody show me the code to use

import java.util.Scanner;    // Needed for the Scanner class


/* To change this template, choose Tools | Templates
* and open the template in the editor.
*/


/**
*
* @author Owner
*/
public class SimpleUserCalculation
{
public static void main(String[] args)
{
String input;
String ExpectedGrade;
short TotalPoints;
final char MIN_LETTER_GRADE = 'a';
final char MAX_LETTER_GRADE = 'f';
char letterGrade;
double average;
byte NumOfGrades;
int grade1, grade2, grade3, grade4, grade5;


// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);


// Display general instructions.
System.out.println("What letter grade do you expect to get?");
ExpectedGrade = keyboard.nextLine();



System.out.println("How many grades do you need to enter?");
NumOfGrades = keyboard.nextByte();


System.out.print("Enter Grade #1: ");
grade1 = keyboard.nextInt();


System.out.print("Enter grade #2: ");
grade2 = keyboard.nextInt();


System.out.print("Enter grade #3: ");
grade3 = keyboard.nextInt();


System.out.print("Enter grade #4: ");
grade4 = keyboard.nextInt();


System.out.print("Enter grade #5: ");
grade5 = keyboard.nextInt();
}
}
if(grade > 0 && < 150){
      
}

You can use that as a starting point. Seeing as you are checking multiple grade I would recommend creating a method that checks the grade.

i would use a nested if else if statements....ive done this already its pretty easy then again not idk complicated i want to post my code but i cant just hand it over i think they would be mad at me lol

i would use a nested if else if statements....ive done this already its pretty easy then again not idk complicated i want to post my code but i cant just hand it over i think they would be mad at me lol

Yes nested if-else would work but for a nice OO design a method would be prefered (heck if you had a ton of grades I would make them their own class but lets not get crazy ;) ). However if you want, ifs are easier. We would not mind you handing over code snippets (we have a section in Daniweb that is all snippets) as long as the OP has shown effort by posting code. The announcements at the top of the page should answer you question about when to hand over code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.