Docsity

Java Code Execution and Input Values - Prof. Ronnie W. Smith, Quizzes of Computer Science

Toggle sidebar
bg1
CSCI 2310
Review Quiz
1. Consider the following Java code segment
int n1, n2, n3;
String s1;
Scanner keyboard = new Scanner(System.in);
n3 = keyboard.nextInt();
s1 = keyboard.nextLine();
n2 = keyboard.nextInt();
n1 = keyboard.nextInt();
n3 = keyboard.nextInt();
Suppose also that the following input is typed in at the keyboard:
28 33 44
112
1798 245
5
What will be the values stored in the variables if the code segment is executed
using the given keyboard input? Where you see whitespace on a line, assume it
is exactly one space.

Partial preview of the text

Download Java Code Execution and Input Values - Prof. Ronnie W. Smith and more Quizzes Computer Science in PDF only on Docsity!

CSCI 2310

Review Quiz

  1. Consider the following Java code segment

int n1, n2, n3; String s1; Scanner keyboard = new Scanner(System.in);

n3 = keyboard.nextInt(); s1 = keyboard.nextLine(); n2 = keyboard.nextInt(); n1 = keyboard.nextInt(); n3 = keyboard.nextInt();

Suppose also that the following input is typed in at the keyboard:

What will be the values stored in the variables if the code segment is executed using the given keyboard input? Where you see whitespace on a line, assume it is exactly one space.