Ask your own question, for FREE!
Computer Science 10 Online
OpenStudy (anonymous):

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

OpenStudy (cybershadow):

Ok so u have done anything yet? or u want to start me from very begining?

OpenStudy (cybershadow):

Ok i m gonna post the whole code O.O

OpenStudy (cybershadow):

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(); } }

OpenStudy (cybershadow):

this code is working, U can define ur own Grading system in the If conditions tho

OpenStudy (anonymous):

actually the output must be same with the video that i share wif u..

OpenStudy (anonymous):

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!!"); } } } }

OpenStudy (anonymous):

OpenStudy (cybershadow):

so isnt ur code complete? What else is left to be done?

OpenStudy (anonymous):

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..

OpenStudy (cybershadow):

List<String> where = new ArrayList<String>(); //declare a new ArrayList element

OpenStudy (cybershadow):

then inside ur for loop

OpenStudy (cybershadow):

where.add("Marks:"+sc.nextint()+" Grade: A ");

OpenStudy (cybershadow):

got it?

OpenStudy (cybershadow):

then print the arraylist in the end

OpenStudy (anonymous):

i'll try it..:)

OpenStudy (anonymous):

thank you..

OpenStudy (cybershadow):

no worries

OpenStudy (anonymous):

i'm still not get it..:(

OpenStudy (cybershadow):

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]);} } }

OpenStudy (cybershadow):

there you go , same as u wanted

OpenStudy (anonymous):

thanks..that question is already answered n pass up to my lect..thank you very much for ur helping..:D

OpenStudy (anonymous):

i try run ur coding and the output same wif what i want..:)

OpenStudy (cybershadow):

glad to help

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!