Find the error of the program segments


Discuss the below:

Q: Find the error(s) in each of the following program segments. Show the corrected statement.

a) System.out.printf( "%sn", 'Happy Birthday' );

b) System.out.printf( "%cn", "Hello" );

c) System.out.printf( "%cn", "This is a string" );

d) The following statement should print "Bon Voyage" with the double quotes:

System.out.printf( ""%s"", "Bon Voyage" );

e) The following statement should print "Today is Friday":

System.out.printf( "Today is %sn", "Monday", "Friday" );

f) System.out.printf( 'Enter your name: ' );

g) System.out.printf( %f, 123.456 );

h) The following statement should print the current time in the format "hh:mm:ss":

Calendar dateTime = Calendar.getInstance();

System.out.printf( "%1$tk:1$%t1:%1$tSn", dateTime );

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Find the error of the program segments
Reference No:- TGS01935384

Now Priced at $20 (50% Discount)

Recommended (92%)

Rated (4.4/5)