Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Please help

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Please help

    ok i got this exersice to do but i'm having a few problems, what i have to do is:

    Write a program that asks the user to input a student exam mark, it then reads in the mark and displays the grade the student has. If the grade is less than 40 display FAILED, if it is between 40 and 50 display 3rd, if it is between 50 and 60 display 2/2 if it is between 60 and 70 display 2/1 and if it is over 70 display 1st. Make sure your program does not except invalid numbers – i.e. it should print out ‘invalid number’ if the user enters a number less than zero or greater than a hundred.

    so this is the code I came up with:

    	/**
    	  This is a program to show the pass grade of a students mark between 0-100
    	  Date:07/02/2011
    	  Author:D.Rayner
    	 */
     
    import java.util.Scanner;
     
    public class studentMarks {
     
     
    	public static void main(String[] args) {
    		int Mark;
     
    		Scanner scan = new Scanner(System.in);
     
    		System.out.println("enter student mark:");
    		Mark = scan.nextInt();
     
    		if (Mark <0);
    		System.out.println("Invalid Number");
    		if (Mark >100);
    		System.out.println("Invalid Number");
    		if (Mark <40);
    		System.out.println("Failed");
    		if (Mark >=40);
    		System.out.println("3rd");
    		if (Mark <50);
    		System.out.println("3rd");
    		if (Mark >=50);
    		System.out.println("2/2");
    		if (Mark <60);
    		System.out.println("2/2");
    		if (Mark >=60);
    		System.out.println("2/1");
    		if (Mark <70);
    		System.out.println("2/1");
    		if (Mark >=70); System.out.println("1st");
    	}
     
    }

    However when I run the program and enter a number it just prints all of the grades, for example if i put 51 it prints failed, 3rd, 2/2, 2/1, 1st and invalid number instead of just printing 2/2.

    any help would be much appriciated.

  2. #2
    Member
    Join Date
    Feb 2011
    Posts
    33
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: Please help


    I made some changes to the code. I replaced all the semicolons at the ends of the if statements with curly braces.


    import java.util.Scanner;
     
    public class studentMarks {
     
        public static void main (String args[]) {
     
            int Mark;
     
            Scanner scan = new Scanner(System.in);
     
            System.out.println("Enter Student Mark: ");
            Mark = scan.nextInt();
     
            if(Mark > 100 || Mark < 0) {
                Mark = -1;
                System.out.println("Invalid Number");
            }
            if(Mark >= 70) {
                System.out.println("1st");
            }
            if(Mark >= 60 && Mark < 70) {
                System.out.println("2/1");
            }
            if(Mark >= 50 && Mark < 60) {
                System.out.println("2/2");
            }
            if(Mark >= 40 && Mark <50) {
                System.out.println("3rd");
            }
            if(Mark < 40 && Mark >= 0) {
                System.out.println("FAILED");
            }
        }
     
    }
    Last edited by WhiteSoup12; February 7th, 2011 at 01:48 PM.

  3. The Following User Says Thank You to WhiteSoup12 For This Useful Post:

    Tate (February 7th, 2011)

  4. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Smile Re: Please help

    Thankyou that helped alot