/    Sign up×
Community /Pin to ProfileBookmark

End-of-file Issue

I’m brand new to Java. Just started a class two weeks ago. I’m trying to get this small piece of code to recognize there will be no more input from the user. The book says type Ctrl Z to tell the program there will be no more input. Nothing happens except my computer just beeps as in an error occurred. To clarify, I’m not typing “Ctrl Z” into the line input. I’m hitting the CTRL key and Z key simultaneously. Here’s the code:

import java.util.Scanner;

public class Grade{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int gradeInput;

while (input.hasNext()) {
gradeInput = input.nextInt();
System.out.printf(“%dn”,gradeInput);
} //end while

} //end main

} //end class

to post a comment
Java

1 Comments(s)

Copy linkTweet thisAlerts:
@criterion9Sep 07.2009 — Usually I check for an empty string entered and break out of the loop when that happens.
×

Success!

Help @Javaboey spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...