SlideShare a Scribd company logo
1 of 2
1. Write a java program that reads a String from the user and prints out each individual character
from the String on it's own line in the command line (i.e. a column instead of a row. Use
System.out.println)
2. Do the same thing as in Assignment6_1, except print it in reverse (down the column).
Solution
A java program that reads a String from the user and prints out each individual character
from the String on it's own line in the command line
public static void main(String[] args) {
// ask the user to enter a string
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter a string: ");
String s = input.nextLine();
// the user to enters a character
System.out.print("Enter a character: ");
char ch = input.nextLine().charAt(0);
int count = count(s, ch);
System.out.println(count);
}
public static int count(String str, char ch) {
int count = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == ch) {
count++;
}
}
return count;
1- Write a java program that reads a String from the user and prints o.docx

More Related Content

Similar to 1- Write a java program that reads a String from the user and prints o.docx

MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfanjanacottonmills
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptxKimVeeL
 
ppt on scanner class
ppt on scanner classppt on scanner class
ppt on scanner classdeepsxn
 
Star pattern programs in java Print Star pattern in java and print triangle ...
Star pattern programs in java Print Star pattern in java and  print triangle ...Star pattern programs in java Print Star pattern in java and  print triangle ...
Star pattern programs in java Print Star pattern in java and print triangle ...Hiraniahmad
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsKuntal Bhowmick
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfmayorothenguyenhob69
 
Anjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjaliSoorej
 
CountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdfCountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdfpremsrivastva8
 

Similar to 1- Write a java program that reads a String from the user and prints o.docx (8)

MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
 
ppt on scanner class
ppt on scanner classppt on scanner class
ppt on scanner class
 
Star pattern programs in java Print Star pattern in java and print triangle ...
Star pattern programs in java Print Star pattern in java and  print triangle ...Star pattern programs in java Print Star pattern in java and  print triangle ...
Star pattern programs in java Print Star pattern in java and print triangle ...
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
Anjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjalisoorej imca133 assignment
Anjalisoorej imca133 assignment
 
CountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdfCountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdf
 

More from cwayne3

I am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docxI am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docxcwayne3
 
I need a short code that is ritten in Visual basic that explains that.docx
I need a short code that is ritten in Visual basic that explains that.docxI need a short code that is ritten in Visual basic that explains that.docx
I need a short code that is ritten in Visual basic that explains that.docxcwayne3
 
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docxi Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docxcwayne3
 
How would you characterize Web 2-0- Describe the set of technologies t.docx
How would you characterize Web 2-0- Describe the set of technologies t.docxHow would you characterize Web 2-0- Describe the set of technologies t.docx
How would you characterize Web 2-0- Describe the set of technologies t.docxcwayne3
 
How would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docxHow would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docxcwayne3
 
1-Put the ionic compounds in order of smallest to largest lattice ener.docx
1-Put the ionic compounds in order of smallest to largest lattice ener.docx1-Put the ionic compounds in order of smallest to largest lattice ener.docx
1-Put the ionic compounds in order of smallest to largest lattice ener.docxcwayne3
 
10- which of the following should be the first step in reviewing he fi.docx
10- which of the following should be the first step in reviewing he fi.docx10- which of the following should be the first step in reviewing he fi.docx
10- which of the following should be the first step in reviewing he fi.docxcwayne3
 
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docxcwayne3
 
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docxcwayne3
 
10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docx10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docxcwayne3
 
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docxcwayne3
 
1-) Which of the following accounting concepts do accountants and audi.docx
1-) Which of the following accounting concepts do accountants and audi.docx1-) Which of the following accounting concepts do accountants and audi.docx
1-) Which of the following accounting concepts do accountants and audi.docxcwayne3
 
1- Why does the initially formed copper hydroxide precipitate dissolve.docx
1- Why does the initially formed copper hydroxide precipitate dissolve.docx1- Why does the initially formed copper hydroxide precipitate dissolve.docx
1- Why does the initially formed copper hydroxide precipitate dissolve.docxcwayne3
 
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
1- Which substance CANNOT have dipole-dipole forces between its molecu.docxcwayne3
 
1-Write an algebraic expression to represent each verbal expression-.docx
1-Write an algebraic expression to represent each verbal expression-.docx1-Write an algebraic expression to represent each verbal expression-.docx
1-Write an algebraic expression to represent each verbal expression-.docxcwayne3
 
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docxcwayne3
 

More from cwayne3 (16)

I am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docxI am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docx
 
I need a short code that is ritten in Visual basic that explains that.docx
I need a short code that is ritten in Visual basic that explains that.docxI need a short code that is ritten in Visual basic that explains that.docx
I need a short code that is ritten in Visual basic that explains that.docx
 
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docxi Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
 
How would you characterize Web 2-0- Describe the set of technologies t.docx
How would you characterize Web 2-0- Describe the set of technologies t.docxHow would you characterize Web 2-0- Describe the set of technologies t.docx
How would you characterize Web 2-0- Describe the set of technologies t.docx
 
How would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docxHow would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docx
 
1-Put the ionic compounds in order of smallest to largest lattice ener.docx
1-Put the ionic compounds in order of smallest to largest lattice ener.docx1-Put the ionic compounds in order of smallest to largest lattice ener.docx
1-Put the ionic compounds in order of smallest to largest lattice ener.docx
 
10- which of the following should be the first step in reviewing he fi.docx
10- which of the following should be the first step in reviewing he fi.docx10- which of the following should be the first step in reviewing he fi.docx
10- which of the following should be the first step in reviewing he fi.docx
 
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
 
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
 
10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docx10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docx
 
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
 
1-) Which of the following accounting concepts do accountants and audi.docx
1-) Which of the following accounting concepts do accountants and audi.docx1-) Which of the following accounting concepts do accountants and audi.docx
1-) Which of the following accounting concepts do accountants and audi.docx
 
1- Why does the initially formed copper hydroxide precipitate dissolve.docx
1- Why does the initially formed copper hydroxide precipitate dissolve.docx1- Why does the initially formed copper hydroxide precipitate dissolve.docx
1- Why does the initially formed copper hydroxide precipitate dissolve.docx
 
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
 
1-Write an algebraic expression to represent each verbal expression-.docx
1-Write an algebraic expression to represent each verbal expression-.docx1-Write an algebraic expression to represent each verbal expression-.docx
1-Write an algebraic expression to represent each verbal expression-.docx
 
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
 

Recently uploaded

An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxCeline George
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxCapitolTechU
 
....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdfVikramadityaRaj
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsCol Mukteshwar Prasad
 
The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...sanghavirahi2
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resourcesdimpy50
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportAvinash Rai
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/siemaillard
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesRased Khan
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17Celine George
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersPedroFerreira53928
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfQucHHunhnh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
 
IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff17thcssbs2
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Mohamed Rizk Khodair
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePedroFerreira53928
 

Recently uploaded (20)

An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 

1- Write a java program that reads a String from the user and prints o.docx

  • 1. 1. Write a java program that reads a String from the user and prints out each individual character from the String on it's own line in the command line (i.e. a column instead of a row. Use System.out.println) 2. Do the same thing as in Assignment6_1, except print it in reverse (down the column). Solution A java program that reads a String from the user and prints out each individual character from the String on it's own line in the command line public static void main(String[] args) { // ask the user to enter a string java.util.Scanner input = new java.util.Scanner(System.in); System.out.print("Enter a string: "); String s = input.nextLine(); // the user to enters a character System.out.print("Enter a character: "); char ch = input.nextLine().charAt(0); int count = count(s, ch); System.out.println(count); } public static int count(String str, char ch) { int count = 0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == ch) { count++; } } return count;