Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Java Program Problems #1

Rating
-
Sold
-
Pages
5
Uploaded on
09-09-2023
Written in
2023/2024

This document contains 4 Java Practise Problems that help in concept building and logic development of Java Programming Language. It consists of questions, and logic break-down, and one of the many methods of writing the code.

Institution
Course

Content preview

Java Practise Problems #1

❖ Replace a given word from a string.
Example : -
Input : I want to eat a pizza.
Replace pizza with cake,
Output : I want to eat a cake.

❖ Write a program to display the number of even and odd
digits in a number input by the user.
Example : -
Input : 7391405
Output : Odd numbers - 5
Even numbers - 2

❖ A program to accept a string and display the number of
uppercase characters, number of lower case characters,
number of special characters and number of digits.
Example : -
Input : %&hV4
Output :
No of Uppercase Characters : 1
No of Lowercsse Characters : 1
No of Numeric Characters : 1
No of Other Characters : 2

❖ Program to display reverse of a number, their difference and
smallest digit in it.
Example : -
Input : 87654321
Output :
Reverse Number : 12345678
Absolute Difference : 75308643
Smallest number : 1

, Program 1 : Replace a given word from a string

Logic :
1. Accept input.
2. Accept the word to be replaced.
3. Use the replace function.


import java.util.Scanner;
public class ReplaceSequence
{
public static void main (String args [])
{
System.out.println("Enter a string.");
Scanner scnr = new Scanner (System.in);
String a = scnr.nextLine();
System.out.println("Enter sequence to be replaced.");
String o = scnr.nextLine();
System.out.println("Enter new sequence.");
String n = scnr.next();
System.out.println("New String : " +a.replace(o,n));
}
}

Written for

Course

Document information

Uploaded on
September 9, 2023
Number of pages
5
Written in
2023/2024
Type
Class notes
Professor(s)
Self
Contains
All classes

Subjects

$4.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
srutibaliga

Get to know the seller

Seller avatar
srutibaliga
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
0
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions