ඩිවලොපර් ගැන්ග්

Commex

Well-known member
  • Nov 29, 2019
    1,768
    1,477
    113
    2.1 Using Scanner Class
    Scanner class එක use කරන්න නම්, මුලින්ම ඒක import කරගන්න ඕනෙ. ඊට පස්සෙ class එකේ නමින් object එකක් හදලා අපිට inputs ගන්න පුලුවන්.

    Java:
    import java.util.Scanner;
    public class Demo {
        public static void main(String[] args) {
            //create Scanner object to read user input
            Scanner sc = new Scanner(System.in);
    
            System.out.print("Enter your name: ");
            //read a String input from the console
            String name = sc.nextLine();
    
            System.out.print("Enter your age: ");
            //read an int input from the console
            int age = sc.nextInt();
    
            System.out.print("Your name is " + name + " and you are " + age + " years old.");
        }
    }

    String inputs ගන්න nextLine(); සහ next(); කියන දෙකම use කරන්න පුළුවන්. හැබැයි වෙනසක් තියෙනවා. next(); දුන්නොත් ඔයා input කරන පලවෙනි වචනෙ විතරයි read කරන්නෙ. උදාහරණයක් විදියට ඔයා John Doe කියලා input කරොත් read වෙන්නෙ John විතරයි. nextLine(); දුන්නම එහෙම නෑ John Doe කියලම read කරනවා.

    ඔයාට int එකක් input කරන්න ඕනෙ නම් nextInt() double නම් nextDouble() වගේ අනිත් data types වලටත් use කරන්න පුළුවන්.

    අනිත් ඒවත් ටික ටික දාන්නම්.. කම්මැලියි අනේ type කරන්න. :sorry: මේක ඉතින් basic idea එක. ප්‍රශ්න එහෙම තිබුනොත් අහන්න. දන්න දෙයක් නම් කියන්නම්. :)
    අම්මෝ මරුනෙ හලෝ.. වෙලාව තියෙන වෙලාවට පොඩ්ඩ පොඩ්ඩ හරි දාන්නකො පුළුවන් නම්. 😶🙄
     
    අම්මෝ මරුනෙ හලෝ.. වෙලාව තියෙන වෙලාවට පොඩ්ඩ පොඩ්ඩ හරි දාන්නකො පුළුවන් නම්. 😶🙄
    Type කරන්න කම්මැලියිනෙ. මම වෙලාවක දාන්නම් :)

    Devops Bootcamp with Nana
    Link
    👆
    ------ Post added on Jul 15, 2024 at 10:09 AM
     

    Kamali18

    Junior member
  • Aug 7, 2024
    27
    27
    13
    පොඩි දේවල් වල ඉදන් ලොකු දේවල් වෙනකන් ඕනෙ එකක් කතා කරමු. දැනුම බෙදාගමු. උදව් කරගමු. හැමෝම දියුණු වෙමු. :love:


    man atthatama kisi deyak danne na matath asayi igana ganna online mokak hari karanna ganna matath kiyala denako
     
    • Love
    Reactions: Geshi95