Hai everyone! im doing java right now and need some help from you guys.. The question said: should have a produced a program which input a numbers of marks from the users and output the grades for each marks..TQ
Ok so u have done anything yet? or u want to start me from very begining?
Ok i m gonna post the whole code O.O
import java.io.*; import java.util.*; public class test { public test() throws IOException{ while(true){ System.out.println("Enter ur marks here:"); Scanner input = new Scanner(System.in); int marks = input.nextInt(); //if conditions, It depends on what ur grading system is if(marks<=100 && marks >80){ System.out.println("Ur Grade is A"); } else if(marks<80 && marks >50){ System.out.println("Ur Grade is B"); } else{ System.out.println("Ur Grade is C"); } } } public static void main(String[] args) throws Exception { // TODO Auto-generated method stub new test(); } }
this code is working, U can define ur own Grading system in the If conditions tho
actually the output must be same with the video that i share wif u..
n this my half code for this stage.. import java.util.Scanner; public class Stage3 { public static void main(String [] args) { Scanner sc; int key_in_marks; int marks; sc = new Scanner(System.in); System.out.print("Enter your numbers of marks? "); key_in_marks = sc.nextInt (); for (int x=1; x<=key_in_marks; x++) { System.out.print("Enter your marks? "); marks = sc.nextInt(); if (marks >= 80 && marks <=100) { System.out.println("Grade A"); } else if (marks >=65 && marks <=79) { System.out.println("Grade B"); } else if (marks >= 50 && marks <=64) { System.out.println("Grade C"); } else if (marks >= 40 && marks <=49) { System.out.println("Grade D"); } else if (marks >= 0 && marks <=39) { System.out.println("Grade E"); } else { System.out.println("INVALID NUMBERS!!"); } } } }
so isnt ur code complete? What else is left to be done?
still not complete yet..i want to display back the marks n grade in one line per student..same like the photo that i attached..
List<String> where = new ArrayList<String>(); //declare a new ArrayList element
then inside ur for loop
where.add("Marks:"+sc.nextint()+" Grade: A ");
got it?
then print the arraylist in the end
i'll try it..:)
thank you..
no worries
i'm still not get it..:(
import java.util.*; public class test { public static void main(String [] args) { Scanner sc; int key_in_marks; int marks; List<String> where = new ArrayList<String>(); sc = new Scanner(System.in); System.out.print("Enter your numbers of marks? "); key_in_marks = sc.nextInt (); for (int x=1; x<=key_in_marks; x++) { System.out.print("Enter your marks? "); marks = sc.nextInt(); if (marks >= 80 && marks <=100) { where.add("Marks:"+marks+" Grade: A "); } else if (marks >=65 && marks <=79) { where.add("Marks:"+marks+" Grade: B "); } else if (marks >= 50 && marks <=64) { where.add("Marks:"+marks+" Grade: C "); } else if (marks >= 40 && marks <=49) { where.add("Marks:"+marks+" Grade: D "); } else if (marks >= 0 && marks <=39) { where.add("Marks:"+marks+" Grade: E "); } else { System.out.println("INVALID NUMBERS!!"); System.exit(0); } } String[] simpleArray = new String[ where.size() ]; where.toArray( simpleArray ); int i; for(i=0;i<where.size();i++){ System.out.println(simpleArray[i]);} } }
there you go , same as u wanted
thanks..that question is already answered n pass up to my lect..thank you very much for ur helping..:D
i try run ur coding and the output same wif what i want..:)
glad to help
Join our real-time social learning platform and learn together with your friends!