I have a program which I am trying to run but I don't know How can I end the scanner input. In the assignment we have this note the we can simple press (ctrl+z) for windows and (ctrl+d) for linux but I am using mac and I have tried it but didn't work.I also tried (cmd +d) and (cmd+z) but didn't work. this is my program:
package F1;
import java.io.PrintStream;
import java.util.Scanner;
public class HatzelKlatzer{
public static final int STARTING_YEAR=1950,
FINAL_YEAR=2050;
PrintStream out;
HatzelKlatzer(){
out=new PrintStream(System.out);
}
//method which will print the percentage
void printPercentage(double percentage){
out.printf("The percentage is: %d",percentage);
}
//TODO Make a method which will read the input if its in range and returns the result
int readInRange(Scanner input,int startDate,int endDate){
int result=input.nextInt();
if(result>endDate || result<startDate){
System.exit(1);
}
return result;
}
//TODO method if month is odd
Boolean oddMonth(Scanner input){
readInRange(input,1,31);
int month=readInRange(input,1,12);
readInRange(input,STARTING_YEAR,FINAL_YEAR);
return month%2 !=0;
}
void start()
{
Scanner in=new Scanner(System.in);
int seizures=0,
numberInOddMonths=0;
//while loop to count the seizures and months odd
while(in.hasNext()){
String date=in.nextLine();
Scanner dateReader=new Scanner(date);
if(oddMonth(dateReader)){
numberInOddMonths +=1;
}
seizures +=1;
}
//calculating the percentage
double percentage=((double)numberInOddMonths/seizures)*100 ;
printPercentage(percentage);
}
public static void main(String[] args){
new HatzelKlatzer().start();
}
}
and it takes input like
12 1 2005
1 1 1995
....etc
But I don't know how to let the scanner know that this is end of the input. Thankyou and please guide me how can it be done...I am just a beginner.
Thanks
Cat.