Posts

Showing posts with the label Strings

Java Practice Set 3

Image
 Java Practice Set 3 QUESTIONS -  SOLUTIONS/CODE ---  package com.company ; public class PS3 { public static void main (String[] args) { // Q1 - Write a JAVA program to covert a string to lowercase String str = "String" ; str = str.toLowerCase() ; System. out .println(str) ; // Q2 - Write a JAVA program to replace spaces with underscore String text = "Write a JAVA program to replace spaces with underscore" ; text = text.replaceAll( " " , "_" ) ; System. out .println(text) ; /* Q3 - Write a JAVA program to fill in a template which looks like below template = "Dear<|name|>, Thanks a lot" Replace 'name' with someone's name*/ String template = "Dear <|name|>, Thanks a lot" ; template = template.replace( "<|name|>" , "Saswata" ) ; System. out .println(template) ; // Q4 - Write a JAVA progr...

Java Tutorial 8 --- "Introduction to Strings"

Image
 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 .print...