Java Tutorial 8 --- "Introduction to Strings"

 Java Tutorial 8 --- "Introduction to Strings"

CODE ---

package com.company;
import java.util.Scanner;

public class Tut8 {
public static void main(String[] args) {
// Introduction to String
// String name = new String("Saswata");
String name = "Saswata"; // Strings are immutable
System.out.print("My name is "); //print doesn't print a new line after print.
System.out.println(name); //println does print a new line after print.
int a = 5;
float b = 6.5545f;
System.out.printf("The value of a is %d and the value of b is %f", a, b);
System.out.println();
System.out.printf("The value of a is %d and the value of b is %.2f", a, b);
System.out.println();
System.out.printf("The value of a is %d and the value of b is %10.2f", a, b);
System.out.println();
System.out.printf("The value of a is %d and the value of b is %10f", a, b);
System.out.println();
System.out.format("The value of a is %d and the value of b is %f", a, b);
System.out.println();
Scanner sc = new Scanner(System.in);
String input_string = sc.nextLine();
System.out.println(input_string);
String input_string2 = sc.next();
System.out.println(input_string2);

}
}


Comments

Popular posts from this blog

JAVA Practice Set 2

Java Practice Set 4

Introduction to Java + Installing Java JDK and IntelliJ IDEA for Java