arrays - How to allow for user input java -


i'm not sure how make code allows user input information, know how create arraylist database not how make once user enters information , presses 'enter' database complete...can me out? (in java)

thanks start tips user input!! helpful! okay have:

import java.util.arraylist; import java.util.list; import java.util.scanner;  public class beststudent  { private string studentname; private string studentgpa;  public beststudent() {  }  public beststudent(string nname, string ngpa) {     this.studentname = nname;     this.studentgpa = ngpa; }  public void setstudentname(string newstudentname) {     studentname = newstudentname; }  public void setstudentgpa(string newstudentgpa) {     studentgpa = newstudentgpa; }  public string getstudentname() {     return studentname; }  public string getstudentgpa() {     return studentgpa; }  public static void main(string[] args) {     list<beststudent> students = new arraylist<beststudent>();     scanner input = new scanner(system.in);      system.out.println("enter number of students");     int countstudents = input.nextint();      for(int = 0; < countstudents; i++)     {     beststudent student = new beststudent();     system.out.println("enter student details" + i);      system.out.println("enter student name");     student.setstudentname(input.next());      system.out.println("enter student gpa");     student.setstudentgpa(input.next());     students.add(student);       }  } } 

is there way make program calculates highest gpa entered? i'm not looking give me answers, push in right direction great, much!!

since know how create arraylist don't need go on that.

look in scanner class. makes getting input easy.

here short example:

scanner input = new scanner(system.in); system.out.print("input: "); string str = input.nextline(); system.out.print(str); 

don't forget import java.util.scanner.

the code instantiate new scanner object, print out "input: " , wait input. once press enter after trying have print out typed.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -