Lineal Posted June 16, 2013 Posted June 16, 2013 Hello , i am newbie in java programming and i need a bit help with a code that i wrote. main idea : User give marks , for example school marks , and especially 4 First mark Second Mark Third Mark Exams' Mark and from the average the system will let the user know if the person who own the marks will " pass " or will "fail". As i tested it works but only with Integers , for example if the average is 40.5 the program will not work but if its an integer it will.! here is the code import java.util.Scanner; public class GradeSystem{ public static void main(String[] args){ Scanner input = new Scanner(System.in); int firstmark; int secondmark; int thirdmark; int exams; int average; System.out.print("Enter The First Mark"); firstmark = input.nextInt(); System.out.print("Enter The Second Mark"); secondmark = input.nextInt(); System.out.print("Enter The Third Mark"); thirdmark = input.nextInt(); System.out.print("Enter The Exams' Mark"); exams = input.nextInt(); average = (firstmark + secondmark + thirdmark + exams) / 4; if(average >= 100){ System.out.printf("Student Pass"); } else if(average <= 60){ System.out.printf("Student Failed"); } } } any idea how to make it work with decimal numbers too?
Lineal Posted June 16, 2013 Author Posted June 16, 2013 just change the int to double thanks! something else! is any way to let the user to put decimal number? thanks!
xdem Posted June 16, 2013 Posted June 16, 2013 just change int to double and nextInt to nextDouble and it will be good
Lineal Posted June 16, 2013 Author Posted June 16, 2013 just change int to double and nextInt to nextDouble and it will be good na se kala re lock it
MissingNo. Posted June 16, 2013 Posted June 16, 2013 You need a double var in order to store a demical.
Lineal Posted June 16, 2013 Author Posted June 16, 2013 You need a double var in order to store a demical. yes , know i know it , thanks
sτrίkε- Posted June 17, 2013 Posted June 17, 2013 You have to read about variable's types! float double = decimal short byte int long = non decimal
Recommended Posts