How to work around java workspace and change to double -


so have write program asks user enter in number of students, asks input name of first student , asks grade of student, goes on next student. example asks how many students , 5, asks me name of first student, , bob smith, asks me grade, 12.5, asks me next students name , on till finish 5 students. sorts in descending order grade. have working, there 2 problems. 1.i cant put in first , last name because of white space. works fine if put in bob not when put bob smith. 2. cant read in double variables grade, int. 5 works not 5.3.here code:

import java.util.*;  public class assignment5 {      public static void main(string[] args) {          scanner input = new scanner(system.in);         system.out.print("enter number of students: ");         int numofstudents = input.nextint();         string[] names = new string[numofstudents];         int[] array = new int[numofstudents];         for(int = 0; < numofstudents; i++) {             system.out.print("enter student's name: ");             names[i] = input.next();             system.out.print("enter student's score: ");             array[i] = input.nextint();         }         selectionsort(names, array);         system.out.println(arrays.tostring(names));     }     public static void selectionsort(string[] names, int[] array) {         for(int = array.length - 1; >= 1; i--) {             string temp;             int currentmax = array[0];             int currentmaxindex = 0;             for(int j = 1; j <= i; j++) {                 if (currentmax > array[j]) {                     currentmax = array[j];                     currentmaxindex = j;                 }             }                    if (currentmaxindex != i) {                 temp = names[currentmaxindex];                 names[currentmaxindex] = names[i];                 names[i] = temp;                 array[currentmaxindex] = array[i];                 array[i] = currentmax;             }         }            } } 

use scanner.nextdouble() instead of nextint().


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -