Hello everyone, I have recently been learning with eclipse and have run into a problem.
The application I am trying to make is a external score keeper that you enter your data in and it processes it.
I have all the other code in my notepad(I write the code while I'm outside) but I have recently run into a problem.
The problem is that when I am trying to get the user to enter the names, it shows an extra 'null|'. The '|' I know why there is, and would be glad if I would not be able to have it there, but do not know why the null is there...
Here is the code:
and output:
Thanks in advance!
import java.util.Scanner; import java.lang.System; public class MainClass { private static Scanner scan; public static void main(String[] args) { int players,rounds,colum,line,count; scan = new Scanner(System.in); System.out.print("How many players? "); System.out.println(); players=scan.nextInt(); System.out.print("How Many Rounds? "); System.out.println(); rounds=scan.nextInt(); int scores[]=new int[players*rounds]; int finalscores[]=new int[players]; String names[]=new String[players]; count=0; for(int ount=0; ount<players; ount++) { int player=ount+1; System.out.println("Enter the name of player "+player+". Press Space & Enter to proceed."); System.out.println(); char symbol='|'; while(symbol!=' ') { names[ount]+=symbol; symbol=scan.findWithinHorizon(".",0).charAt(0); } System.out.println(names[ount]); } } }
How many players? 2 How Many Rounds? 1 Enter the name of player 1. Press Space & Enter to proceed. Adam null|Adam Enter the name of player 2. Press Space & Enter to proceed. Dave null|Dave