Page 136 - CA_Blue( J )_Class9
P. 136
Program 3 Write a program to take a string from the user and display it.
1 import java.util.*;
2 class string_input
3 {
4 public static void main(String[] args)
5 {
6 Scanner sc= new Scanner(System.in); //System.in is a standard input
stream
7 System.out.print("Enter the string: ");
8 String str= sc.nextLine(); //reads string
9 System.out.print("Entered string: "+str);
10 }
11 }
You will get the following output:
Program 4 Write a program to demonstrate the use of print and println statements.
1 import java.io.*;
2 class print_statement
3 {
4 public static void main(String[] args)
5 {
6 System.out.print("This is ");
7 System.out.println("the differentce between ");
8 System.out.print(" print and println statements.");
9 }
10 }
134 Touchpad Computer Applications-IX

