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

14th Aug 2018, 4:11 PM
Kartikey Gupta
Kartikey Gupta - avatar
3 ответов
+ 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(); } }
14th Aug 2018, 8:39 PM
Jang Jaeung
Jang Jaeung - avatar
0
we have to input a paragraph not a sentences
15th Aug 2018, 6:48 AM
Kartikey Gupta
Kartikey Gupta - avatar
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); } } }
16th Aug 2018, 9:04 PM
Jang Jaeung
Jang Jaeung - avatar