Posts

SOLUTION FOR JAVA DATE AND TIME.

Image
QUESTION IS The Calendar class is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for manipulating the calendar fields, such as getting the date of the next week. You are given a date. You just need to write the method,  , which returns the  day  on that date. To simplify your task, we have provided a portion of the code in the editor. For example, if you are given the date  , the method should return   as the day on that date. Input Format A single line of input containing the space separated month, day and year, respectively, in       format. Constraints Output Format Output the correct day in capital letters. Sample Input 08 05 2015 Sample Output WEDNESDAY Explanation The day on August   th     was   WEDNESDAY .   TO SOLVE THIS QUESTION YOU NEED IMPORT JAVA "time" PACKAGE BY "import java.time.*; in this package you will use the method "Lo

SOLUTION FOR STRING TO INT IN JAVA

  QUESTION IS You are given an integer  , you have to convert it into a string. Please complete the partially completed code in the editor. If your code successfully converts   into a string   the code will print " Good job ". Otherwise it will print " Wrong answer ".  can range between   to   inclusive. Sample Input 0 100 Sample Output 0 Good job WAYS TO CONVERT TO AN INTEGER TO STRING IS Here are 2 ways to convert an int to a String String s = String . valueOf ( n ); String s = Integer . toString ( n ); AND THE SOLUTION IS import  java.util.*; import  java.security.*; public   class  Solution {   public   static   void  main(String[] args) {   DoNotTerminate.forbidExit();    try  {    Scanner in =  new  Scanner(System.in);     int  n = in .nextInt();    in.close();     //String s=???; Complete this line below     String s = Integer.toString(n);             if  (n == Integer.parseInt(s)) {     System.out.println( "Good job" );    }  else  {     Sy

SOLUTION FOR STATIC INITIALIZER BLOCK IN JAVA

  QUESTION IS   Static initialization blocks are executed when the class is loaded, and you can initialize static variables in those blocks. It's time to test your knowledge of  Static initialization blocks .  You are given a class  Solution  with a  main  method. Complete the given code so that it outputs the area of a parallelogram with breadth   and height  . You should read the variables from the standard input. If   or    , the output should be  "java.lang.Exception: Breadth and height must be positive"  without quotes. Input Format There are two lines of input. The first line contains  : the breadth of the parallelogram. The next line contains  : the height of the parallelogram. Constraints Output Format If both values are greater than zero, then the  main  method must output the area of the  parallelogram . Otherwise, print  "java.lang.Exception: Breadth and height must be positive"  without quotes. Sample input 1 1 3 Sample output 1 3 Sample input 2 -1 2