🌙 DARK

Wrapper Class

 


Wrapper Class – Integer

 

This program is to illustrate the Integer Wrapper class.

 

Write a program that accepts an “Integer” class type value as input and invokes some of the methods defined in the Integer Wrapper class.

 

All functions should be performed using the methods defined in the Integer class.

The link to download the template code is given below
Code Template
 

Input and Output Format:
 

Refer sample input and output for formatting specifications.
All the double values should be displayed upto 1 decimal place.
All text in bold corresponds to input and the rest corresponds to output.

 

Sample Input and Output :
 

Enter an integer

540

The binary equivalent of 540 is 1000011100

The hexadecimal equivalent of 540 is 21c

The octal equivalent of 540 is 1034

Byte value of 540 is 28

Short value of 540 is 540

Long value of 540 is 540

Float value of 540 is 540.0

Double value of 540 is 540.0




@MRProgrammer89 


CREATE CLASS < Main :


import java.util.Scanner;

public class Main {

public static void main(String[] args) throws Exception {

  Scanner sc = new Scanner(System.in);

          System.out.println("Enter an integer");

      int no = sc.nextInt();

          double d = no;

          byte b = (byte) no;

          short s = (short) no;

          long l =no;

          float f =no;

          System.out.println("The binary equivalent of "+no+" is "+Integer.toBinaryString(no));

          System.out.println("The hexadecimal equivalent of "+no+" is "+Integer.toHexString(no));

          System.out.println("The octal equivalent of "+no+" is "+Integer.toOctalString(no));

          System.out.println("Byte value of "+no+" is "+b);

          System.out.println("Short value of "+no+" is "+s);

          System.out.println("Long value of "+no+" is "+l);

          System.out.println("Float value of "+no+" is "+f);

          System.out.println("Double value of "+no+" is "+(d));

}

}








Wrapper Class


Write a Java program to print the following static values defined in the Float Wrapper Class

The maximum exponent of a float can hold
The maximum value a float can hold
Number of bits used to represent a float value


The link to download the template code is given below
Code Template

 Input and Output Format:

There is no input to this program.
Refer to sample output for formatting specifications.

 Sample Output:
Maximum exponent:127
Maximum value :3.4028235E38
Number of bits:32



@MRProgrammer89 


CREATE CLASS < Main :


public class Main {

    public static void main(String[] args) {

        

System.out.println("Maximum exponent :"+Float.MAX_EXPONENT+" ");

        System.out.println("Maximum value :"+Float.MAX_VALUE+" ");

        System.out.println("Number of bits :"+Float.SIZE+" ");

}

}



String Reversal

 

Write a program to reverse a given string.

 

Input Format:

 

Input consists of a string.

 

Output Format:

 

Output displays the given string in the reverse order.

Refer sample input and output for formatting specifications.

[All text in bold corresponds to input and the rest corresponds to output.]

 

Sample Input and Output:

 

Enter a string to reverse

Jhon

Reverse of the string is nhoJ



@MRProgrammer89 


CREATE CLASS < Main :



import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

        System.out.println("Enter a string to reverse");

        String input = sc.nextLine();

        StringBuffer length = new StringBuffer(input);

        //int length = input.length();

        length.reverse();

        

       

        System.out.println("Reverse of the string is "+length);

}

}





String API : startsWith() : Illustration


Write a program to illustrate the use of the method startsWith() defined in the string API.

 

Input and Output Format:
 

Refer sample input and output for formatting specifications.

All text in bold corresponds to input and the rest corresponds to output.

 

Sample Input and Output 1:
 

Enter the string

Technology

Enter the start string

Logic

"Technology" does not start with "Logic"

 

Sample Input and Output 2:

Enter the string

Technology

Enter the start string

Tech

"Technology" starts with "Tech"




@MRProgrammer89 


CREATE CLASS < Main :


import java.util.Scanner;

public class Main {

public static void main(String[] args) throws Exception {

      Scanner sc = new Scanner(System.in);

      System.out.println("Enter the string");

      String name = sc.nextLine();

      System.out.println("Enter the start string");

      String start = sc.nextLine();

      

      if(name.startsWith(start)) {

          System.out.println("\""+name+"\""+" starts with "+"\""+start+"\"");

          

      }

      else {

          System.out.println("\""+name+"\""+" does not start with "+"\""+start+"\"");

          

      }

      

      

      

}

}




@MRProgrammer89 






MOTIVATION :


    “The way we spend our time defines who we are 


Although we may not see each other as often as we’d like, distance is no match for the bond that we share. Thank you for coming to visit. It was fantastic to catch up.


VISITE MORE BLOGS




THANK YOU....😊




Post a Comment

Thanks for reading the blog. We hope it was useful to you and that you learned something new. Will always be writing on new and interesting topics, so you can visit our website to know the latest updates of our blogs. Thank You!

Previous Post Next Post

Contact Form