• Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Have any question?

(+91) 98222 16647
info@simplycoding.in
RegisterLogin
Simply Coding
  • Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Java Introduction

Java print/println exam questions

  • Categories Java Introduction, Introduction to Java, Java
Java print exam questions

Here is a quick revision of key items you need to remember before attempting Java print / println questions

    1. println() prints the string and THEN moves to next line.
    2. print() prints the string and DOES NOT move to next line.
    3. \n (newline) Moves the cursor to next line. print (“\n”) is equivalent to println()
    4. \t (tab) Leaves 4 or 8 bye of space before printing next.
    5. \”, \\ are examples of how a slash in front of quotes etc. help us to print punctuators which have special meaning in java.
    6. ASCII code for A – Z = 65 – 90
    7. ASCII code for a – z = 97 – 122
    8. To do integer manipulations typecast them to int e.g. int c =  (int)’A’;
    9. To print char equivalent of a number, typecast to char e.g. System.out.print ((char)65);
    10. To convert to uppercase do minus 32 To convert to lowercase do plus 32
    11. Do a double check if you are using int or char for all ASCII code questions
    12. Also attempt print questions which are clubbed with switch and loops

Lets Start!

  1. What is the output of the following statements?
    1. System.out.print(“Simply “);

            System.out.println(“Coding”);

Choose the correct option:  

    1. Simply Coding
    2. Simply
      Coding

Ans. (i) is the correct output.

Explanation: System.out.print() does not add a new line at the end because of which ‘Coding’ gets printed on the same line as ‘Simply’.

  1. What is the output of the following?

char c = ‘A’;
short m = 26;
int n = c + m;
System.out.println(n);

Ans:  91.

Explanation: This is because adding ‘char’ with integer data type ‘short’, the lower data type ‘char’ converted to integer ‘short’. i.e. ‘A’ becomes 65, so 65+26 is 91

  1. Write the output for the following:

System.out.print(“Simply\nt” + “\n” + “\\Coding”);  

Ans.

Simply
t
\Coding

  1. Write the Output:

char ch= ‘F’;
int m=ch;
m=m+5;
System.out.println(m+ ” ” +ch);

Ans. 75 F

Explanation:

ch = ‘F’
int m = ch; — ASCII value of ‘F’ i.e. 70 will be assigned to m
m = m + 5 = 70 + 5 = 75
System.out.println(m+ ” ” +ch); — 75 F

  1. Give the output and show the dry run too.

public class output1
{
static int m=0,n=0;
public static void main()
{
int m=10, x=20;
{
int n=30;
System.out.println(“m+n=”+(m+n));
}
x+=m+n;
System.out.println(“x=”+x);
}
}

Ans

m+n=40 // (value of ‘n’ is 0 at initialize n=0, but in code block value of ‘n’ is change 0 to 30, so; n=30, m=10=> 30+10 =40)
x=30      //  (n=0, m=10 and x=20 => 20+=10+0;)

  1. State the result of the following statement.

System.out.print(“Simply Coding \n”);
System.out.print(“Online \tTutor \t”);
System.out.print(“and Course.”);

Ans.

    • Simply Coding
    • Online       Tutor        and Course.
  1. State the result of the following statement.

System.out.print(“Welcome \n to \t “);
System.out.println(“Simply Coding “);
System.out.print(“Online Courses”);

Ans.

Welcome
to         Simply Coding
Online Courses

  1. What is the output of following code?

class StringExample{
public static void main(String args[]){
char a= ‘a’;
char b= ‘A’;
System.out.println (“Sum:”+a+b);
System.out.println(“Difference:”+((int)a-(int)b));
}
}

Ans.

Sum:aA

Difference:32

  1. What will be the output when the following code segment is executed?

System.out.println (“Welcome to \”Simply Coding!\”programming is fun!”);

Ans. Welcome to “Simply Coding!”programming is fun!

  1. Write the output of the following:

System.out.println(“Simply”+“\n”+“Coding”);

Ans. Simply

         Coding

  • Share:
author avatar
Simply Coding

Previous post

Java Tokens and Data types Practice Questions
June 7, 2020

Next post

Crack Java Math Problems
June 7, 2020

You may also like

Types of Programming Languages
Types of Programming Languages
16 June, 2021
Java Theory – Java Basics
Java Theory – Java Basics
15 June, 2021
Input-Output in Java
Input/Output in Java
17 January, 2021

Leave A Reply Cancel reply

You must be logged in to post a comment.

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String
Simply Coding Computer Courses for School                Privacy Policy     Terms of Use     Contact Us

© 2021 Simply Coding

Login with your site account

Lost your password?

Not a member yet? Register now

Register a new account

Are you a member? Login now