Java දන්න කෙනෙක් පොඩි හෙල්ප් එකක්...

MiyuB

Well-known member
  • Nov 20, 2013
    1,459
    367
    83
    ලංකාවේ...
    bump

    මෙන්න මෙකට කාටහරි කෝඩ් එකක් ගහල දෙන්න බැරිද.. ලොකු උද්ව්වක්...
     
    Last edited:

    imhotep

    Well-known member
  • Mar 29, 2017
    14,861
    8
    35,448
    113
    Write a Java program to solve the following problem: If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used? NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of ”and” when writing out numbers is in compliance with British usage.


    මෙන්න මෙකට කාටහරි කෝඩ් එකක් ගහල දෙන්න බැරිද.. ලොකු උද්ව්වක්...
    https://coderanch.com/t/437744/java/Project-Euler
     

    Persiaus

    Active member
  • Jan 8, 2017
    78
    19
    28
    import java.util.Scanner;

    public class NumberCounter {

    public static void main(String[] args) {
    int count = 0;
    System.out.println("Enter Sentence");
    Scanner sc = new Scanner(System.in);
    String sentence = sc.nextLine();
    count = sentence.length();
    char[] sentenceArray = sentence.toCharArray();
    char[] constrains = { '-', ' ', ',' };

    for (char charactor : sentenceArray) {

    for (char constrain : constrains) {
    if (charactor == constrain) {
    count--;
    }
    }
    }

    System.out.println(count);

    }

    }