• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to make this number point?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
========
public class TestTikus {
public static void main (String[] args) {
Tikus t = new Tikus();

t.setWeight(10);
System.out.println("Tikus ni berat:"+ t.getWeight());


}
}
=========
public class Tikus {
private float weight;
public float getWeight() {
return weight;
}

public void setWeight(float newWeight) {
if (newWeight > 0) {
weight = newWeight;
}
}
}
=======
output:10.0


how can i get the output....let say..i want 10.3
how can i do that?

and..how can i get input from user?
in others words,the programme prompt and ask the user to give the weight

thanks for helping me~
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I understand the first part of your question. The program is just printing whatever value you send to the method.

In order to get input from the user, you can use java.util.Scanner.
[ October 09, 2006: Message edited by: Keith Lynn ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"javac java",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by javac java:
========
public class TestTikus {
public static void main (String[] args) {
Tikus t = new Tikus();

t.setWeight(10);
System.out.println("Tikus ni berat:"+ t.getWeight());


}
}
=========
public class Tikus {
private float weight;
public float getWeight() {
return weight;
}

public void setWeight(float newWeight) {
if (newWeight > 0) {
weight = newWeight;
}
}
}
=======
output:10.0


how can i get the output....let say..i want 10.3
how can i do that?

and..how can i get input from user?
in others words,the programme prompt and ask the user to give the weight

thanks for helping me~

 
MV Krishna
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use BufferedReader to read the input from the command line.

Example:
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();
reply
    Bookmark Topic Watch Topic
  • New Topic