SlideShare ist ein Scribd-Unternehmen logo
1 von 3
Downloaden Sie, um offline zu lesen
Code:
//I have choosen a scenario of my shopping where I went to buy a T-Shirt
import java.util.*;
import java.io.*;
class Test{
public static void main (String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter the amount You have: ");
String str = input.nextLine();
String[] strl = str.split(" ");
int strlen = strl.length;
if (strlen == 1){
System.out.println("First word: "+strl[0]);
}else if (strlen == 2){
System.out.println("First word: "+strl[0]);
System.out.println("Second word: "+strl[1]);
}else if (strlen == 3){
System.out.println("First word: "+strl[0]);
System.out.println("Second word: "+strl[1]);
System.out.println("Third word: "+strl[2]);
}else if (strlen == 4){
System.out.println("First word: "+strl[0]);
System.out.println("Second word: "+strl[1]);
System.out.println("Third word: "+strl[2]);
System.out.println("Fourth word: "+strl[3]);
}else{
System.out.println("First word: "+strl[0]);
System.out.println("Second word: "+strl[1]);
System.out.println("Third word: "+strl[2]);
System.out.println("Fourth word: "+strl[3]);
System.out.println("Fourth word: "+strl[4]);
}
System.out.println(" Middle 10 characters: "+ str.substring(0,10));
}
}
Output:
Enter the amount You have: Hello my name is computer science 1001
First word: Hello
Second word: my
Third word: name
Fourth word: is
Fourth word: computer
Middle 10 characters: is compute
Solution
Code:
//I have choosen a scenario of my shopping where I went to buy a T-Shirt
import java.util.*;
import java.io.*;
class Test{
public static void main (String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter the amount You have: ");
String str = input.nextLine();
String[] strl = str.split(" ");
int strlen = strl.length;
if (strlen == 1){
System.out.println("First word: "+strl[0]);
}else if (strlen == 2){
System.out.println("First word: "+strl[0]);
System.out.println("Second word: "+strl[1]);
}else if (strlen == 3){
System.out.println("First word: "+strl[0]);
System.out.println("Second word: "+strl[1]);
System.out.println("Third word: "+strl[2]);
}else if (strlen == 4){
System.out.println("First word: "+strl[0]);
System.out.println("Second word: "+strl[1]);
System.out.println("Third word: "+strl[2]);
System.out.println("Fourth word: "+strl[3]);
}else{
System.out.println("First word: "+strl[0]);
System.out.println("Second word: "+strl[1]);
System.out.println("Third word: "+strl[2]);
System.out.println("Fourth word: "+strl[3]);
System.out.println("Fourth word: "+strl[4]);
}
System.out.println(" Middle 10 characters: "+ str.substring(0,10));
}
}
Output:
Enter the amount You have: Hello my name is computer science 1001
First word: Hello
Second word: my
Third word: name
Fourth word: is
Fourth word: computer
Middle 10 characters: is compute

Weitere ähnliche Inhalte

Ähnlich wie CodeI have choosen a scenario of my shopping where I went to bu.pdf

import java.util.Scanner; public class Palin { public static v.pdf
import java.util.Scanner; public class Palin { public static v.pdfimport java.util.Scanner; public class Palin { public static v.pdf
import java.util.Scanner; public class Palin { public static v.pdfLAMJM
 
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...Nithin Kumar,VVCE, Mysuru
 
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
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming AssignmentCoding Assignment Help
 
1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdfAnkitchhabra28
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfoptokunal1
 
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdfactocomputer
 

Ähnlich wie CodeI have choosen a scenario of my shopping where I went to bu.pdf (8)

import java.util.Scanner; public class Palin { public static v.pdf
import java.util.Scanner; public class Palin { public static v.pdfimport java.util.Scanner; public class Palin { public static v.pdf
import java.util.Scanner; public class Palin { public static v.pdf
 
The Art of Clean Code
The Art of Clean CodeThe Art of Clean Code
The Art of Clean Code
 
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
 
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
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
 
1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
 
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdf
 

Mehr von anwarsadath111

(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdfanwarsadath111
 
We use a base (in this case sodium bicarbonate) during the separatio.pdf
  We use a base (in this case sodium bicarbonate) during the separatio.pdf  We use a base (in this case sodium bicarbonate) during the separatio.pdf
We use a base (in this case sodium bicarbonate) during the separatio.pdfanwarsadath111
 
While computing the dilluted earnings per share Dividend paid on Pre.pdf
While computing the dilluted earnings per share Dividend paid on Pre.pdfWhile computing the dilluted earnings per share Dividend paid on Pre.pdf
While computing the dilluted earnings per share Dividend paid on Pre.pdfanwarsadath111
 
There are several ways in which the gene regulation in eukaryotes di.pdf
There are several ways in which the gene regulation in eukaryotes di.pdfThere are several ways in which the gene regulation in eukaryotes di.pdf
There are several ways in which the gene regulation in eukaryotes di.pdfanwarsadath111
 
The water must be boiled to remove traces of dissolved carbon dioxid.pdf
The water must be boiled to remove traces of dissolved carbon dioxid.pdfThe water must be boiled to remove traces of dissolved carbon dioxid.pdf
The water must be boiled to remove traces of dissolved carbon dioxid.pdfanwarsadath111
 
adsorb onto silica gel Solu.pdf
  adsorb onto silica gel                                      Solu.pdf  adsorb onto silica gel                                      Solu.pdf
adsorb onto silica gel Solu.pdfanwarsadath111
 
Solution Plants show different types of symptoms when there is an.pdf
Solution Plants show different types of symptoms when there is an.pdfSolution Plants show different types of symptoms when there is an.pdf
Solution Plants show different types of symptoms when there is an.pdfanwarsadath111
 
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdfQuick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdfanwarsadath111
 
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdf
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdfQues-1) What is the most likely cause of a throat infection in a 6-y.pdf
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdfanwarsadath111
 
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdfPart1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdfanwarsadath111
 
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdfPerformance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdfanwarsadath111
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfanwarsadath111
 
P = 212option ASolutionP = 212option A.pdf
P = 212option ASolutionP = 212option A.pdfP = 212option ASolutionP = 212option A.pdf
P = 212option ASolutionP = 212option A.pdfanwarsadath111
 
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdfOSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdfanwarsadath111
 
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdfOption 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdfanwarsadath111
 
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdfNH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdfanwarsadath111
 
No. of shares outstanding = Total assets x weight of equity price .pdf
No. of shares outstanding = Total assets x weight of equity  price .pdfNo. of shares outstanding = Total assets x weight of equity  price .pdf
No. of shares outstanding = Total assets x weight of equity price .pdfanwarsadath111
 
molarity = moles volume = 2.0 x 10-3 mol (18.51000) L = 0.11 M.pdf
molarity = moles  volume = 2.0 x 10-3 mol  (18.51000) L = 0.11 M.pdfmolarity = moles  volume = 2.0 x 10-3 mol  (18.51000) L = 0.11 M.pdf
molarity = moles volume = 2.0 x 10-3 mol (18.51000) L = 0.11 M.pdfanwarsadath111
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfanwarsadath111
 

Mehr von anwarsadath111 (20)

(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
 
We use a base (in this case sodium bicarbonate) during the separatio.pdf
  We use a base (in this case sodium bicarbonate) during the separatio.pdf  We use a base (in this case sodium bicarbonate) during the separatio.pdf
We use a base (in this case sodium bicarbonate) during the separatio.pdf
 
While computing the dilluted earnings per share Dividend paid on Pre.pdf
While computing the dilluted earnings per share Dividend paid on Pre.pdfWhile computing the dilluted earnings per share Dividend paid on Pre.pdf
While computing the dilluted earnings per share Dividend paid on Pre.pdf
 
There are several ways in which the gene regulation in eukaryotes di.pdf
There are several ways in which the gene regulation in eukaryotes di.pdfThere are several ways in which the gene regulation in eukaryotes di.pdf
There are several ways in which the gene regulation in eukaryotes di.pdf
 
The water must be boiled to remove traces of dissolved carbon dioxid.pdf
The water must be boiled to remove traces of dissolved carbon dioxid.pdfThe water must be boiled to remove traces of dissolved carbon dioxid.pdf
The water must be boiled to remove traces of dissolved carbon dioxid.pdf
 
adsorb onto silica gel Solu.pdf
  adsorb onto silica gel                                      Solu.pdf  adsorb onto silica gel                                      Solu.pdf
adsorb onto silica gel Solu.pdf
 
Solution Plants show different types of symptoms when there is an.pdf
Solution Plants show different types of symptoms when there is an.pdfSolution Plants show different types of symptoms when there is an.pdf
Solution Plants show different types of symptoms when there is an.pdf
 
SF4SolutionSF4.pdf
SF4SolutionSF4.pdfSF4SolutionSF4.pdf
SF4SolutionSF4.pdf
 
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdfQuick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
 
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdf
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdfQues-1) What is the most likely cause of a throat infection in a 6-y.pdf
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdf
 
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdfPart1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
 
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdfPerformance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdf
 
P = 212option ASolutionP = 212option A.pdf
P = 212option ASolutionP = 212option A.pdfP = 212option ASolutionP = 212option A.pdf
P = 212option ASolutionP = 212option A.pdf
 
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdfOSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
 
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdfOption 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
 
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdfNH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
 
No. of shares outstanding = Total assets x weight of equity price .pdf
No. of shares outstanding = Total assets x weight of equity  price .pdfNo. of shares outstanding = Total assets x weight of equity  price .pdf
No. of shares outstanding = Total assets x weight of equity price .pdf
 
molarity = moles volume = 2.0 x 10-3 mol (18.51000) L = 0.11 M.pdf
molarity = moles  volume = 2.0 x 10-3 mol  (18.51000) L = 0.11 M.pdfmolarity = moles  volume = 2.0 x 10-3 mol  (18.51000) L = 0.11 M.pdf
molarity = moles volume = 2.0 x 10-3 mol (18.51000) L = 0.11 M.pdf
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdf
 

Kürzlich hochgeladen

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Kürzlich hochgeladen (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

CodeI have choosen a scenario of my shopping where I went to bu.pdf

  • 1. Code: //I have choosen a scenario of my shopping where I went to buy a T-Shirt import java.util.*; import java.io.*; class Test{ public static void main (String[] args){ Scanner input = new Scanner(System.in); System.out.print("Enter the amount You have: "); String str = input.nextLine(); String[] strl = str.split(" "); int strlen = strl.length; if (strlen == 1){ System.out.println("First word: "+strl[0]); }else if (strlen == 2){ System.out.println("First word: "+strl[0]); System.out.println("Second word: "+strl[1]); }else if (strlen == 3){ System.out.println("First word: "+strl[0]); System.out.println("Second word: "+strl[1]); System.out.println("Third word: "+strl[2]); }else if (strlen == 4){ System.out.println("First word: "+strl[0]); System.out.println("Second word: "+strl[1]); System.out.println("Third word: "+strl[2]); System.out.println("Fourth word: "+strl[3]); }else{ System.out.println("First word: "+strl[0]); System.out.println("Second word: "+strl[1]); System.out.println("Third word: "+strl[2]); System.out.println("Fourth word: "+strl[3]); System.out.println("Fourth word: "+strl[4]); } System.out.println(" Middle 10 characters: "+ str.substring(0,10)); }
  • 2. } Output: Enter the amount You have: Hello my name is computer science 1001 First word: Hello Second word: my Third word: name Fourth word: is Fourth word: computer Middle 10 characters: is compute Solution Code: //I have choosen a scenario of my shopping where I went to buy a T-Shirt import java.util.*; import java.io.*; class Test{ public static void main (String[] args){ Scanner input = new Scanner(System.in); System.out.print("Enter the amount You have: "); String str = input.nextLine(); String[] strl = str.split(" "); int strlen = strl.length; if (strlen == 1){ System.out.println("First word: "+strl[0]); }else if (strlen == 2){ System.out.println("First word: "+strl[0]); System.out.println("Second word: "+strl[1]); }else if (strlen == 3){ System.out.println("First word: "+strl[0]); System.out.println("Second word: "+strl[1]); System.out.println("Third word: "+strl[2]); }else if (strlen == 4){ System.out.println("First word: "+strl[0]); System.out.println("Second word: "+strl[1]); System.out.println("Third word: "+strl[2]);
  • 3. System.out.println("Fourth word: "+strl[3]); }else{ System.out.println("First word: "+strl[0]); System.out.println("Second word: "+strl[1]); System.out.println("Third word: "+strl[2]); System.out.println("Fourth word: "+strl[3]); System.out.println("Fourth word: "+strl[4]); } System.out.println(" Middle 10 characters: "+ str.substring(0,10)); } } Output: Enter the amount You have: Hello my name is computer science 1001 First word: Hello Second word: my Third word: name Fourth word: is Fourth word: computer Middle 10 characters: is compute