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

The solution to a java code execution problem where the input values from the user are given and the task is to determine the stored values in the variables. The code segment involves using a scanner object to read user input and assign values to variables n1, n2, and n3, which are initially declared as integers, and a string variable s1. The user input is given as 28 33 44 112 1798 245 5.

Typology: Quizzes

Pre 2010

Uploaded on 02/25/2010

koofers-user-84c
koofers-user-84c 🇺🇸

5

(1)

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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.