Results 1 to 6 of 6
Like Tree2Likes
  • 1 Post By Norm
  • 1 Post By Norm

Thread: need help in this code ????

  1. #1
    eng.master89 is offline Member
    Join Date
    Jan 2012
    Posts
    9
    Rep Power
    0

    Unhappy need help in this code ????

    I'm new in the world of Java and i make a program to calculate the score of students in the materials, but I want to break when the user enters
    a negative value???

    Java Code:
    import java.util.Scanner;
    public class StudentGrade{	
    	public static void main(String[] args){
    
    		double x,y,z,w,v ;
    		Scanner kb = new Scanner(System.in);
    
    		System.out.print("\n Score of Subject 1: ");
    		x = kb.nextDouble(); 
    		
                    System.out.print("\n Score of Subject 2: ");
    		y = kb.nextDouble();
    		
                    System.out.print("\n Score of Subject 3: ");
    		z = kb.nextDouble();
    		
                    System.out.print("\n Score of Subject 4: ");
    		w = kb.nextDouble();
    		
                    System.out.print("\n Score of Subject 5: ");
    		v = kb.nextDouble();
    		
                    double total = w+v+x+y+z;
    		double average = total / 5.0;
    		System.out.print("\n Total Score = "+total+" \t|Average = "+average);
    		System.out.println("\n Good Bye!!!");
    
    	}
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: need help in this code ????

    but I want to break when the user enters a negative value???
    Please explain what you mean by "break".
    You need to learn how to use an array and a loop.
    The break statement will cause the execution to exit the loop.

  3. #3
    eng.master89 is offline Member
    Join Date
    Jan 2012
    Posts
    9
    Rep Power
    0

    Default Re: need help in this code ????

    i mean when entering a negative value the program tells you that it's not allowed to use negative values

    thanks

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: need help in this code ????

    What do you want to do if there is a negative value?
    You can use an if statement to test if the value is negative and output a message.
    Then what?
    eng.master89 likes this.

  5. #5
    eng.master89 is offline Member
    Join Date
    Jan 2012
    Posts
    9
    Rep Power
    0

    Default Re: need help in this code ????

    thanks a lot

    i did it now

    i'm studying with my self would you mind to tell me What the best books that you advise me to study them ?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: need help in this code ????

    Sorry, I learned java a long time ago and do not have any current books to recommend.
    eng.master89 likes this.

Similar Threads

  1. Replies: 3
    Last Post: 08-10-2011, 09:17 AM
  2. Replies: 0
    Last Post: 08-07-2011, 08:32 PM
  3. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  4. Replies: 1
    Last Post: 03-04-2010, 11:19 AM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •