java(day6)

 A string is a sequence of characters.

A string is instantiated as follows:

String name;

name = new String(“Harry”);

String is a class but can be used as a data type.

Strings are immutable and cannot be changed.

String name = “Harry”’

(Here, name is a reference, and “Harry” is an object.)

Different ways to print in Java

We can use the following ways to print in Java:

  • out.print() // No newline at the end
  • out.println() // Prints a new line at the end
  • out.printf()
  • out.format()

System.out.printf(“%c”,ch)

{ %d for int

  %f for float

  %c for char

  %s for string }

 

Comments

Popular posts from this blog

java chapter11 practice question on abstruct class and interfaces

DAY 12 -AZURE DP900(Microsoft Azure Data Fundamentals: Explore non-relational data in Azure)

java exercise4