|
hi..
check the following code..
<script type="text/javascript">
var indMoney = function (v)
{
v = (Math.round((v - 0) * 100)) / 100;
v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
v = String(v);
var ps = v.split('.'),
whole = ps[0],
sub = ps[1] ? '.' + ps[1] : '.00',
r = /(\d+)(\d{3})/;
while (r.test(whole))
{
whole = whole.replace(r, '$1' + ',' + '$2');
}
v = whole + sub;
return v;
}
</script>
The result of the above function is displaying like this 123,123,123.00
but i want in this format 12,31,23,123.00 i.e indian currency format..
|
|
|
|
|
This is the Java forum, Javascript is next one down.
I must get a clever new signature for 2011.
|
|
|
|
|
More than that he has asked the same question in the Questions section too...lol
|
|
|
|
|
|
WTF - damn, you indian programmers like to get penalized - ain't ya!
NumberFormat @ Oracle JavaDoc[^]
That's how we do it in Java - pretty simple.
regards
Torsten
I never finish anyth...
|
|
|
|
|
Except his question is regarding Javascript.
I must get a clever new signature for 2011.
|
|
|
|
|
You should put your code in code block by using "pre" tag it makes readability of code. and next I am suggesting you as same as Richard suggest you should move your question to there-[JavaScript Forum][^] for quick response
|
|
|
|
|
Hello
I am beginning in the Java language, at the beginning of my university
i want code to calculator program in java language
|
|
|
|
|
you should start with books & something like this[^]
besides this a help forum not free source codes site.
|
|
|
|
|
Try "java calculator" in Google; you will get lots of samples. Alternatively go to The Java Tutorials[^] for lots of good information.
I must get a clever new signature for 2011.
|
|
|
|
|
you can get plenty of articles and links when you will search it on Google like this[^]
you can go there[^] and there[^] to learn how to create Calculator in Java.
|
|
|
|
|
i was creating a new app and was thinking of creating an additional feature as to give additional security to lock all desktop components , and i never want to loose focus from app before one makes a login.
So i tried this:
1. created a JFrame/JWindow to test made it pretty much workable by setting it always on top true & with fullscreen only.
2. fullscreen mode doesnt have any problem. But with a small frame in center when someone click out of it on desktop system looses its focus.
3. i tried all possible solutions as window deactivated event jframe focus lost etc. but they just acted one time, as you click out of it they will bring focus once again but after that on second click this thing doesn't work.
4. i googled and found this tutorial Lock Windows Desktop[^] but its in VB , Nothing in Java!??
5. i guess it would be nice to have an virtual desktop or something like above tutorial created in java, so i want suggestions is it possible in java as in many forums i read about java limitations over native codes i really want to going on it and putting such thing on sourceforge, if its possible in it.
Regards
Alok sharma
We always wonder what comes next and neglect what is available...
|
|
|
|
|
It is unliekly you will eb able to do this unless you call out to native window API's from the JVM. Not a good idea.
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
|
|
|
|
|
well, you can fire some OS Commands through the java.lang.runtime[^]
it might be possible to use it. But I don't think you can block the native OS so much, that it doesn't react. Some call it a safety barrier - some call it a limitation.
regards
Torsten
I never finish anyth...
|
|
|
|
|
Description doesn't make much sense unless you are creating a kiosk/cash register type of application.
If that is what you want then you are going to need to do some work in something besides java. You can research how by researching 'kiosk' techniques.
|
|
|
|
|
well i have heard it first time ('kiosk technique') so i will look into that.......
|
|
|
|
|
import java.io.*;
import java.util.*;
class LinkedList<T>
{
private Node head;
private Node last;
private T data;
public LinkedList()
{
head = null;
}
public boolean isEmpty()
{
return (head==null);
}
public void addToHead (T val)
{
Node n = new Node (val);
n.next = head;
head = n;
}
private class Node
{
public T data;
public Node next;
Node (T val)
{
data = val;
next = null;
}
}
public void delete(T val)
{
delete(head, val);
}
public Node delete (Node curr, T val)
{
Comparable <T> temp = (Comparable<T>)val;
if (curr==null)
{
System.out.println("list empty");
}else if ( temp.compareTo(curr.data)==0){
curr = curr.next;
}else{
curr.next = delete(curr.next, val);
}
return curr;
}
public String toString()
{
String str ="";
Node curr = head;
while(curr!=null)
{
str = str + curr.data + " ";
curr = curr.next;
}
return str + "\n";
}
}
class Link
{
public static void main(String[] arg)
{
LinkedList<Integer> s1 = new LinkedList<Integer>();
s1.addToHead(23);
s1.addToHead(78);
s1.addToHead(100);
s1.delete(23);
System.out.println(s1.toString());
}
}
I am writing the code above to delete a node from a linkedlist using recursion.
Questions
1. Is there another way I can rewrite the method without using Comparable?
2. The program compiles but give the following error all the time, How can i rectify this?
Note: C:\Users\antonio\Desktop\Link2.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
|
|
|
|
|
T is an Object and supports equals(Object) . Use that instead of a comparitor which is more suitable for ordered items. If the item T will always be comparible then you can define it as such:
class LinkedList<T extends Comparable<T>>
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
|
|
|
|
|
As regards your second question, if you follow the compiler's advice and recompile with -Xlint:unchecked, you get the following warning:
warning: [unchecked] unchecked cast
found : T
required: java.lang.Comparable<T>
Comparable<T> temp = (Comparable<T>) val;
1 warning
In other words, there is no guarantee that the val being passed into the delete method will actually be a Comparable at runtime, so the cast may fail. This isn't a compilation error, because it will work if you do pass in a Comparable, but there is no way for the compiler to enforce this, so it is letting you know that this may be unsafe.
And as someone else has already pointed out, it's not clear why you are using compareTo instead of equals.
|
|
|
|
|
Dear programmers,
I am a new student of CS, I am learning Java on Eclipse. I have an assignment which to reverse an input text - it is called palindrome. I coded but errors, I wonder if you all can help me as I do not even know that what wrong with this code.
public class firstsubroutine {
public static void main (String[] args){
TextIO.putln("Enter the palindrome : ");
TextIO.put("? ");
String line = TextIO.getln();
line = line.toLowerCase();
if (isString(line) = true){
reverse(line);
String reversed = reverse(line);
if (line == reversed){
System.out.println ("Stripped : " + line);
System.out.println ("Reversed : " + reversed);
System.out.println ("This IS a palindrome.");
}
else{
System.out.println ("Stripped : " + line);
System.out.println ("Reversed : " + reversed);
System.out.println ("This is NOT a palindrome.");
}
}
}
static void isString (String isStr){
int i;
boolean isBoolean;
for (i = 0; i < isStr.length(); i++){
char ch = isStr.charAt(i);
if (Character.isLetter(ch)){
isBoolean = true;
}
else{
isBoolean = false;
}
}
}
static void reverse(String reStr){
int i;
String reverse = "";
for (i = reStr.length() - 1; i >= 0; i++){
reverse = reverse + reStr.charAt(i);
}
}
}
|
|
|
|
|
I found few mistakes. I've commented them and your program is working fine..
import java.util.Scanner;
public class firstsubroutine {
public static void main (String[] args){
Scanner in = new Scanner(System.in);
System.out.println("Enter the palindrome : ");
System.out.println("? ");
String line = in.next();
line = line.toLowerCase();
if (isString(line) == true){
String reversed = reverse(line);
if (line.equals(reversed)){
System.out.println ("Stripped : " + line);
System.out.println ("Reversed : " + reversed);
System.out.println ("This IS a palindrome.");
}
else{
System.out.println ("Stripped : " + line);
System.out.println ("Reversed : " + reversed);
System.out.println ("This is NOT a palindrome.");
}
}
}
static boolean isString (String isStr){
int i;
for (i = 0; i < isStr.length(); i++){
char ch = isStr.charAt(i);
if (!Character.isLetter(ch))
{
return false;
}
}
return true;
}
static String reverse(String reStr){
int i;
String reverse = "";
for (i = reStr.length() - 1; i >= 0; i--){
reverse = reverse + reStr.charAt(i);
}
return reverse;
}
}
Shivam Kalra
|
|
|
|
|
Shivam Kalra,
Many and many thanks for you support. I tested and worked very well.
Visoth
|
|
|
|
|
No problem bro.
I'm a CS student too. And homework sucks.
|
|
|
|
|
Oh, my friend!!!! I wish I could help you. What language do you use for your homework?
Visoth
|
|
|
|
|
We are using combination of C++ and JAVA.
|
|
|
|