JAVA WADDOOOOOOOO warellaaa

firazrox

Member
Dec 26, 2009
1,054
193
0
cyberඅවකශායෙ
:confused:

mata mea code ekata user input karana number eka check karanna one 900 walata wada wadida kiyala wadinam invalid kiyala awith ayeth number eka input karanna kiyala kiyanna ona, mama loops dala try kala eth errors enawa godak pls help me

import java.util.Scanner;
import javax.swing.JOptionPane;
class NumberToString
{

public enum hundreds {OneHundred, TwoHundred, ThreeHundred, FourHundred, FiveHundred, SixHundred, SevenHundred, EightHundred, NineHundred}
public enum tens {Twenty, Thirty, Forty, Fifty, Sixty, Seventy, Eighty, Ninety}
public enum ones {One, Two, Three, Four, Five, Six, Seven, Eight, Nine}
public enum denom {Thousand, Lakhs, Crores}
public enum splNums { Ten, Eleven, Twelve, Thirteen, Fourteen, Fifteen, Sixteen, Seventeen, Eighteen, Nineteen}
public static String text = "";

public static void main(String[] args)
{
JOptionPane.showMessageDialog(null," Welcome to my maths app");
long num=0;
System.out.println("input number between one and nine hundred");
Scanner sc = new Scanner(System.in);
num = sc.nextInt();
int rem = 0;
int i = 0;
long r = num;

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

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

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


System.out.print("Ones : ");
for(int h=0; h<Ones; h++){
System.out.print("o");
}
System.out.println("");
while(num > 0)
{
if(i == 0){
rem = (int) (num % 1000);
printText(rem);
num = num / 1000;
i++;
}
else if(num > 0)
{
rem = (int) (num % 100);
if(rem > 0)
text = denom.values()[i - 1]+ " " + text;
printText(rem);
num = num / 100;
i++;
}
}
if(i > 0)
System.out.println(text);
else
System.out.println("Zero");
}

public static void printText(int num)
{
if(!(num > 9 && num < 19))
{
if(num % 10 > 0)
getOnes(num % 10);

num = num / 10;
if(num % 10 > 0)
getTens(num % 10);

num = num / 10;
if(num > 0)
getHundreds(num);
}
else
{
getSplNums(num % 10);
}
}

public static void getSplNums(int num)
{
text = splNums.values()[num]+ " " + text;
}

public static void getHundreds(int num)
{
text = hundreds.values()[num - 1]+ " " + text;
}

public static void getTens(int num)
{
text = tens.values()[num - 2]+ " " + text;
}

public static void getOnes(int num)
{
text = ones.values()[num - 1]+ " " + text;
}
}
 
Last edited:
  • Like
Reactions: whizzkid

markhaloce

Member
Mar 7, 2013
10,298
677
0
17
The Real North
I tried like that but it gives a lot of errors can you include it in the code itself pls ?
:confused:

ජාව රන් කරන්න මොකුත් ide එකක්වත් කම්පයිලර් එකක්වත් නෑ :no: :no: :no:
ඕක තමා බං තියරිය...
ඉන්පුට් එක ගන්නයි ඖටිපුට් එක දෙන්නයි විතරයි තියෙන්නෙ... :yes: :yes: :yes:
 

SHdinesh

Member
Dec 30, 2014
36
2
0
package demos;

import java.util.Scanner;
import javax.swing.JOptionPane;

class NumberToString {

public enum hundreds {

OneHundred, TwoHundred, ThreeHundred, FourHundred, FiveHundred, SixHundred, SevenHundred, EightHundred, NineHundred
}

public enum tens {

Ten, Twenty, Thirty, Forty, Fifty, Sixty, Seventy, Eighty, Ninety
}

public enum ones {

One, Two, Three, Four, Five, Six, Seven, Eight, Nine
}

public enum denom {

Thousand, Lakhs, Crores
}

public enum splNums {

Ten, Eleven, Twelve, Thirteen, Fourteen, Fifteen, Sixteen, Seventeen, Eighteen, Nineteen
}
public static String text = "";

public static void main(String[] args) {
JOptionPane.showMessageDialog(null, " Welcome to my maths app");
long num = 0;
System.out.println("input number between one and nine hundred");
Scanner sc = new Scanner(System.in);
num = sc.nextInt();
if (num > 900) {
JOptionPane.showMessageDialog(null, "Number is greater than 900. Please re-enter your number");
//NumberToString num1 = new NumberToString();
} else {
int rem = 0;
int i = 0;
long r = num;

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

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

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

System.out.print("Ones : ");
for (int h = 0; h < Ones; h++) {
System.out.print("o");
}
System.out.println("");
while (num > 0) {
if (i == 0) {
rem = (int) (num % 1000);
printText(rem);
num = num / 1000;
i++;
} else if (num > 0) {
rem = (int) (num % 100);
if (rem > 0) {
text = denom.values()[i - 1] + " " + text;
}
printText(rem);
num = num / 100;
i++;
}
}
if (i > 0) {
System.out.println(text);
} else {
System.out.println("Zero");
}
}

}

public static void printText(int num) {
if (!(num > 9 && num < 19)) {
if (num % 10 > 0) {
getOnes(num % 10);
}

num = num / 10;
if (num % 10 > 0) {
getTens(num % 10);
}

num = num / 10;
if (num > 0) {
getHundreds(num);
}
} else {
getSplNums(num % 10);
}
}

public static void getSplNums(int num) {
text = splNums.values()[num] + " " + text;
}

public static void getHundreds(int num) {
text = hundreds.values()[num - 1] + " " + text;
}

public static void getTens(int num) {
text = tens.values()[num - 1] + " " + text;
}

public static void getOnes(int num) {
text = ones.values()[num - 1] + " " + text;
}
}

Now try it. ;)
 
Last edited:

ජොසී

Well-known member
  • May 29, 2014
    5,206
    4,453
    113
    Padavi Sripura
    මොකද්ද බං මීමුත්තගෙ ඉඳලා ජීවන කතාව code එකේ දැම්මද උඹ?
    කෙටියෙං අදාල ටික දාහංකො. බලන්න හිතෙන්නෑ නෙ! :no:
     

    firazrox

    Member
    Dec 26, 2009
    1,054
    193
    0
    cyberඅවකශායෙ
    package demos;

    import java.util.Scanner;
    import javax.swing.JOptionPane;

    class NumberToString {

    public enum hundreds {

    OneHundred, TwoHundred, ThreeHundred, FourHundred, FiveHundred, SixHundred, SevenHundred, EightHundred, NineHundred
    }

    public enum tens {

    Ten, Twenty, Thirty, Forty, Fifty, Sixty, Seventy, Eighty, Ninety
    }

    public enum ones {

    One, Two, Three, Four, Five, Six, Seven, Eight, Nine
    }

    public enum denom {

    Thousand, Lakhs, Crores
    }

    public enum splNums {

    Ten, Eleven, Twelve, Thirteen, Fourteen, Fifteen, Sixteen, Seventeen, Eighteen, Nineteen
    }
    public static String text = "";

    public static void main(String[] args) {
    JOptionPane.showMessageDialog(null, " Welcome to my maths app");
    long num = 0;
    System.out.println("input number between one and nine hundred");
    Scanner sc = new Scanner(System.in);
    num = sc.nextInt();
    if (num > 900) {
    JOptionPane.showMessageDialog(null, "Number is greater than 900. Please re-enter your number");
    //NumberToString num1 = new NumberToString();
    } else {
    int rem = 0;
    int i = 0;
    long r = num;

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

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

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

    System.out.print("Ones : ");
    for (int h = 0; h < Ones; h++) {
    System.out.print("o");
    }
    System.out.println("");
    while (num > 0) {
    if (i == 0) {
    rem = (int) (num % 1000);
    printText(rem);
    num = num / 1000;
    i++;
    } else if (num > 0) {
    rem = (int) (num % 100);
    if (rem > 0) {
    text = denom.values()[i - 1] + " " + text;
    }
    printText(rem);
    num = num / 100;
    i++;
    }
    }
    if (i > 0) {
    System.out.println(text);
    } else {
    System.out.println("Zero");
    }
    }

    }

    public static void printText(int num) {
    if (!(num > 9 && num < 19)) {
    if (num % 10 > 0) {
    getOnes(num % 10);
    }

    num = num / 10;
    if (num % 10 > 0) {
    getTens(num % 10);
    }

    num = num / 10;
    if (num > 0) {
    getHundreds(num);
    }
    } else {
    getSplNums(num % 10);
    }
    }

    public static void getSplNums(int num) {
    text = splNums.values()[num] + " " + text;
    }

    public static void getHundreds(int num) {
    text = hundreds.values()[num - 1] + " " + text;
    }

    public static void getTens(int num) {
    text = tens.values()[num - 2] + " " + text;
    }

    public static void getOnes(int num) {
    text = ones.values()[num - 1] + " " + text;
    }
    }

    Now try it. ;)

    did you run it ? for me it compiles ok but gets so many errors when I try to tun it :(:no::no:
     

    firazrox

    Member
    Dec 26, 2009
    1,054
    193
    0
    cyberඅවකශායෙ
    ජොසී;18368683 said:
    මොකද්ද බං මීමුත්තගෙ ඉඳලා ජීවන කතාව code එකේ දැම්මද උඹ?
    කෙටියෙං අදාල ටික දාහංකො. බලන්න හිතෙන්නෑ නෙ! :no:

    mekai scene eka

    mama code kala programme ekak eke mata user input karana number eka 900 wada wadinam loop wenne ona udata aye eth mama do loops and while dala baluwa arahen meehen errors enawa wena ewa wala, eth loops nathuwa hodata run wenawa :(
     

    firazrox

    Member
    Dec 26, 2009
    1,054
    193
    0
    cyberඅවකශායෙ
    ජාව රන් කරන්න මොකුත් ide එකක්වත් කම්පයිලර් එකක්වත් නෑ :no: :no: :no:
    ඕක තමා බං තියරිය...
    ඉන්පුට් එක ගන්නයි ඖටිපුට් එක දෙන්නයි විතරයි තියෙන්නෙ... :yes: :yes: :yes:
    yaka gahanna wage errors bn :(
     

    ජොසී

    Well-known member
  • May 29, 2014
    5,206
    4,453
    113
    Padavi Sripura
    Code:
    Scanner sc = new Scanner(System.in);
    num = sc.nextInt();

    replace these two lines with following.


    Code:
    bool isValid = false;
    int num;
    while(!isValid){
    	sc = new Scanner(System.in);
    	num = sc.nextInt();
    	if(num < 900){
    		isValid = true;
    		break;
    	}else{
    		isValid = false;
    		//Display invalid message
    	}
    }
     

    firazrox

    Member
    Dec 26, 2009
    1,054
    193
    0
    cyberඅවකශායෙ
    ජොසී;18368755 said:
    Code:
    Scanner sc = new Scanner(System.in);
    num = sc.nextInt();

    replace these two lines with following.


    Code:
    bool isValid = false;
    int num;
    while(!isValid){
    	sc = new Scanner(System.in);
    	num = sc.nextInt();
    	if(num < 900){
    		isValid = true;
    		break;
    	}else{
    		isValid = false;
    		//Display invalid message
    	}
    }

    28 errors while compiliing :no::no::no::no::no:
     

    SHdinesh

    Member
    Dec 30, 2014
    36
    2
    0
    This programme ran very well under my environment and after some small changes I able to get the correct output using it.