Results 1 to 6 of 6
Thread: need help in this code ????
- 01-02-2012, 01:39 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 9
- Rep Power
- 0
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!!!"); } }
- 01-02-2012, 01:52 AM #2
Re: need help in this code ????
Please explain what you mean by "break".but I want to break when the user enters a negative value???
You need to learn how to use an array and a loop.
The break statement will cause the execution to exit the loop.
- 01-02-2012, 01:58 AM #3
Member
- Join Date
- Jan 2012
- Posts
- 9
- Rep Power
- 0
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
- 01-02-2012, 02:00 AM #4
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?
- 01-02-2012, 02:10 AM #5
Member
- Join Date
- Jan 2012
- Posts
- 9
- Rep Power
- 0
Re: need help in this code ????
thanks a lot
-.gif)
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 ?
- 01-02-2012, 02:11 AM #6
Similar Threads
-
My code was not executed properly.It will jumping to exception handling.my code is
By vinay4051 in forum EclipseReplies: 3Last Post: 08-10-2011, 09:17 AM -
servlet include method copying sorce code and executing source code as output how to
By shamkuma2k in forum Advanced JavaReplies: 0Last Post: 08-07-2011, 08:32 PM -
C server code - Java CLient Code _ TCP Connection Problem
By rmd22 in forum NetworkingReplies: 0Last Post: 02-21-2011, 11:50 AM -
can any one pls send me a sample code for calling a jsp code in swings
By sniffer139 in forum AWT / SwingReplies: 1Last Post: 03-04-2010, 11:19 AM -
Generating Code Automatically Using Custom code Template In Eclipse
By JavaForums in forum EclipseReplies: 1Last Post: 04-26-2007, 03:52 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks