simple java help

firazrox

Member
Dec 26, 2009
1,054
193
0
cyberඅවකශායෙ
podi assignment ekakata udawwak oneeee

java poddak danna aya poddak udaw karannako

menna mekai scene eka

api dan number ekak enter kalama eka menna mehema display wenna ona


if user enters 234 the application should
display the following

Hundreds|–
OO

Tens |–
OOO

Ones |– OOOO

abacus ekaka wage

help me pls :confused::confused::confused: repp++ dennam :)
 
Last edited:

sanoka

Well-known member
  • Dec 6, 2007
    5,147
    1,233
    113
    If i got the question correctly

    class tt {

    public static void main(String args[]){

    int r = 234;
    System.out.print("Thousands : ");
    System.out.println(r/1000);
    System.out.print("Hundreds : ");
    System.out.println(r/100);
    System.out.print("Tens : ");
    System.out.println(r/10);
    }

    }
     
    • Like
    Reactions: firazrox

    firazrox

    Member
    Dec 26, 2009
    1,054
    193
    0
    cyberඅවකශායෙ
    If i got the question correctly

    we're supposed to display how many thousands and hundreds by "o" i guess here's the full question

    Display a welcome message
    “Welcome to my maths app”

    · Prompt the user to input number
    between one and hundred

    · Validate the marks i.e. the
    application should only accept the input within the range. If the user enters a
    mark that is not within the range, the application should display the
    appropriate error message and prompt the user to enter another number.

    · Display the entered number in
    text

    I.e. if user enters 234 the application should
    display “Two hundred and thirty four”

    · Display the entered number in
    an abacus

    I.e. if user enters 234 the application should
    display the following

    Hundreds |–
    OO

    Tens |–
    OOO

    Ones |– OOOO

    thanks in advance
     
    Last edited:

    sanoka

    Well-known member
  • Dec 6, 2007
    5,147
    1,233
    113
    As the question only allowed numbers between 1-100

    class tt {

    public static void main(String args[]){

    int r = 234;

    int hundreds = r/100;
    int Tens = (r-hundreds*100)/10;
    int Ones = r-(hundreds*100+Tens*10);

    System.out.print("Hundreds : ");
    for(int h=0; h<hundreds; h++){
    System.out.print(0);
    }
    System.out.println("");

    System.out.print("Tens : ");
    for(int h=0; h<Tens; h++){
    System.out.print(0);
    }
    System.out.println("");


    System.out.print("Ones : ");
    for(int h=0; h<Ones; h++){
    System.out.print(0);
    }
    System.out.println("");
    }

    }
     

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,868
    1
    9,644
    113
    Gampaha
    Prompt the user to input number
    between one and hundred

    I.e. if user enters 234 the application should display “Two hundred and thirty four”

    :lol::lol: dafaq??? :rofl:
     

    Voltage

    Well-known member
  • Feb 6, 2012
    21,723
    1
    15,120
    113
    If i got the question correctly



    Code:
    class tt {
    
    public static void main(String args[]){
    
    int r = 234;
    System.out.print("Thousands : ");
    System.out.println(r/1000);
    System.out.print("Hundreds : ");
    System.out.println(r/100);
    System.out.print("Tens : ");
    System.out.println(r/10);
    }
    
    }

    @ firazrox - you may use
    • rounding functions to the above code >> and convert them to int
    • use a for loop for each 10/100/1000 to print STAR "*" or any symbol >> the running count for the loops should be the ints you got in the previous steps
     
    • Like
    Reactions: firazrox

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,868
    1
    9,644
    113
    Gampaha
    @ firazrox - you may use
    • rounding functions to the above code >> and convert them to int
    • use a for loop for each 10/100/1000 to print STAR "*" or any symbol >> the running count for the loops should be the ints you got in the previous steps
    :no: 234/10 = 23
     

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,868
    1
    9,644
    113
    Gampaha
    Code:
    class <>{
        psvm{
            Scanner Object;
            int number = User input;
            
            if(validation ok){
    
    [B]            int ones = number % 10;            
                int tens = number / 10 % 10
                int hundreds = number / 100;[/B]
                
                for loop(){
                    sout();
                }
            }else{
                appropriate error msg
            }    
        }
    }
     

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,868
    1
    9,644
    113
    Gampaha
    int ones = number % 10;
    int tens = number / 10 % 10;
    int hundreds = number / 100 % 10;


    oya widiyata use karanna.. mama kalin uda dunna code eke hundreds eka use karanna epa..
     
    • Like
    Reactions: firazrox