0
Program to input a paragraph and obtain length of each sentence.
I love sololearn.It is awesome. I love sololearn-- 16 It is awesome--13
3 odpowiedzi
+ 1
this???
import java.util.Scanner;
public class main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Type sentences :");
String sentence1 = sc.nextLine();
String sentence2 = sc.nextLine();
String sentence3 = sc.nextLine();
int length1 = sentence1.replaceAll("\\s", "").length();
int length2 = sentence2.replaceAll("\\s", "").length();
int length3 = sentence3.replaceAll("\\s", "").length();
System.out.println(length1);
System.out.println(length2);
System.out.println(length3);
sc.close();
}
}
0
we have to input a paragraph not a sentences
0
like this then??
import java.util.ArrayList;
import java.util.Scanner;
public class main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Hello, type a paragraph : (enter again to end paragraph)");
ArrayList<String>paragraph = new ArrayList<String>();
String line;
do{
line = sc.nextLine();
paragraph.add(line);
}while(!line.equals(""));
for(String temp : paragraph){
int length = temp.replaceAll("\\s","").length();
if(!temp.equals(""))
System.out.println(temp + " | " + length);
}
}
}