🌙 DARK

Wrapper Class JAVA


Wrapper Class – Integer 

 This program is to illustrate the parseInt() method defined in the Integer Wrapper class.


Write a program that accepts 3 String values as input and invokes some of the methods defined in the Integer Wrapper class.

Refer sample input and output. 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 text in bold corresponds to input and the rest corresponds to output.




Sample Input and Output :

Enter the binary number
111
Enter the octal number
11
Enter the hexadecimal number
1F
The integer value of the binary number 111 is 7
The integer value of the octal number 11 is 9
The integer value of the hexadecimal number 1F is 31



@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 the binary number");

        String  first = sc.nextLine();

        System.out.println("Enter the octal number");

        String  second = sc.nextLine();

        System.out.println("Enter the hexadecimal number");

        String  third = sc.nextLine();

        

        int decimal=Integer.parseInt(first,2); 

        int oct = Integer.parseInt(second,8);

        int hex = Integer. parseInt(third, 16);

        

        System.out.println("The integer value of the binary number "+first+" is "+decimal);

        System.out.println("The integer value of the octal number "+second+" is "+oct);

        System.out.println("The integer value of the hexadecimal number "+third+" is "+hex);

}

}






Replacing the string


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

Two companies enter into a Marketing Agreement and they prepare an Agreement Draft. After that one of the company changes its name. The name changes need to be made in the Agreement Draft as well. Write a program to perform the name changes in the agreement draft.


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 :

Enter the content of the document
Pure is a private organisation. Pure is a product based company. NewApp is a Pure product

Enter the old name of the company
Pure
Enter the new name of the company
Pixel
The content of the modified document is
Pixel is a private organisation. Pixel is a product based company. NewApp is a Pixel product

@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 the content of the document");

        String first = sc.nextLine();

        System.out.println("Enter the old name of the company");

        String second = sc.nextLine();

        System.out.println("Enter the new name of the company");

        String third = sc.nextLine();

        

        String replaceString=first.replace(second,third);

        System.out.println("The content of the modified document is"+"\n"+replaceString);

}

}



String API : endsWith() : Illustration


Write a program to illustrate the use of the method endsWith() 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 end string

Tech

"Technology" does not end with "Tech"

 

Sample Input and Output 2:
 

Enter the string

Jhon

Enter the end string

on

"Jhon" ends with "on"


@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 the string");

        String first = sc.nextLine();

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

        String last = sc.nextLine();

        

        if(first.endsWith(last)) {

            System.out.println("\""+first+"\""+" ends with "+"\""+last+"\"");

        }

        else{

            System.out.println("\""+first+"\""+" does not end with "+"\""+last+"\"");

        }

}

} 


@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