Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in /home/cmwhittington/theteach.ca/libraries/gantry/core/gantry.class.php on line 1044
Data Types Quiz
Text Size
Sunday, May 09, 2021

Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/cmwhittington/theteach.ca/components/com_komento/helpers/string.php on line 327

Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/cmwhittington/theteach.ca/components/com_komento/helpers/string.php on line 329

Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/cmwhittington/theteach.ca/components/com_komento/helpers/string.php on line 330

Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/cmwhittington/theteach.ca/components/com_komento/helpers/string.php on line 331

Projects

Data Types Quiz

Part A: Predict what the variables k and z would equal in the program shown below. Show all floating point results to two decimal places.

/15 Marks

int i, j, k;
double x, y, z;
i = 5;
j = 7;
x = 5.0;
y = 7.0;

  1. k = i + j;
  2. k = j % i * 2;
  3. z = x / y;
  4. z = i / j;
  5. z = (double) i + j / 3;
  6. z = i + (double) j / 3;
  7. z = i + j / 3.0;
  8. z = (double) ( i + j / 3 );
  9. k = (int) ( x + y / 3.0 );
  10. k = (int) x + (int) y / 3;
  11. z = i / j * 3.0;
  12. z = 3.0 * i / j;
  13. z = 3 / ( (double) i / j );
  14. z = 3 / ( i / j );
  15. z = (x / y)(i / y);

      Part B
  16. Please write the output (what will be on the console screen) for the following java code.

/15 Marks

/*
*Created: C. Whittington
*Date: Oct. 29 2003
*Purpose: This is a file used to test student's understanding of
* data types in java. Students are asked what the output
* of the program will be.
*/

import java.awt.*;
import java.awt.event.*;

class DataTypesQuiz
{

public static void main(String args[])
{

System.out.println("Starting Data Types...");

boolean bool=true;
char char1='a';
int int1=13;
double double1=4.5;


String str1 = new String ("abcdefg");

//System.out.println (bool+(char*5));
System.out.println (bool+"\n"+char1);
System.out.println (int1+"\n"+double1+"\n"+str1);

bool = !true;
char1 = 'q';
System.out.println (char1+"\n");
char1++;
char1++;
int1 = int1 + int1 *10;

double1 = int1 / 2;

System.out.println ("Changed Values");
System.out.println (bool+"\n"+char1);
str1 = str1 + (++char1);
System.out.println (int1 + double1+"\n"+str1);
System.out.println (int1+"\n"+double1);
System.out.println ("The End.");

}

}

Leave your comments

0
terms and condition.
  • No comments found
Parent Category: ICS4U