Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Core Java Programming

Have Programming Question? Ask it here!
 
 
 


Manish
Core Java Programming
1 Answer(s)      5 years and 8 months ago
Posted in : Java Beginners



Advertisement
View Answers

December 4, 2008 at 5:22 AM


Hi friend,

Code to solve the problem :

import java.util.Random; // Only the Random class
import java.util.*;
class RandomNumberEx
{
public static void main(String[] args)
{
String strResult="";
Random r = new Random();
float f = r.nextFloat();
float randomNumber = Round(f,1);


////If Else

if(randomNumber<0.5)
{
System.out.println("The Value is less than 0.5");
}
else if(randomNumber>=0.5)
{
System.out.println("The value is greater than 0.5");
}

////Ternary Operator

strResult = randomNumber < 0.5 ? "The Value is less than 0.5" : "The value is greater than 0.5"; // get absolute value of i
System.out.print(strResult);
}
public static float Round(float Rval, int Rpl) {
float p = (float)Math.pow(10,Rpl);
Rval = Rval * p;
float tmp = Math.round(Rval);
return (float)tmp/p;
}
}

Thanks


Related Tutorials/Questions & Answers:
core java programming question
core java programming question  How to write a java program to list the customer names arrived to a restuarant on a particular date in alphabetical order with arguments as 1 filename yymmdd cust   Hi Friend, Try
core Java programming
core Java programming  Hi, Thanks for ur previous answers.... I need some of these answers also... Bharathi Indian Cuisine is a leading Indian...;TIME:HHMMSS;ITEM1:QTY:PRICE;ITEM2:PRICE2;] They are looking for a Java Program
Advertisements
Core Java Programming - Java Beginners
Core Java Programming  Write a program in Java which initializes the starting date as your birthday and displays the date 90 days later in the format day name, month name, day, year   Hi friend, Code to solve
Core Java Programming - Java Beginners
Core Java Programming  Write a program in Java which generates a random number between 0 and 1. If the number generated is less than 0.5 then the program must print ?The Value is less than 0.5? and if the number generated
core java
core java  how to display characters stored in array in core java
core java
core java  basic java interview question
CORE JAVA
CORE JAVA  CORE JAVA PPT NEED WITH SOURCE CODE EXPLANATION CAN U ??   Core Java Tutorials
core java
core java  i need core java material   Hello Friend, Please visit the following link: Core Java Thanks
core java
core java  Hi, can any one expain me serialization,Deseralization and exterenalization in core java
core java
core java  Hi, can any one exain me the concept of static and dynamic loading in core java
Core JAva
Core JAva  how to swap 2 variables without temp in java
core java
core java  how can we justify java technology is robust
CORE JAVA
CORE JAVA  What is Garbage collection in java? What is the role of a developer for garbage collection
core java
core java  its compulsory to save file name and class name is same in java
Core Java
Core Java  How to execute cmd command through java?? Give Code of them
core java
core java  write a java program to view product details from product table
Core Java
Core Java  Hi, Can any one please share the code for Binary search in java without using builtin function
Core Java
Core Java  Please write a Java Program to design login form and store the values in file & validate and display the MainForm
core java
core java  In java primitive variables will get its default value automatically after declaration. Then why it is mandatory to initialize a variable before using
core java
core java  Hello sir,What is logic behinde the core java programms,How may programmas are there,for example,sorting of two numbers,grade of the student details,fibonice serice,paldroma,incremting of the program,asscedding
core java
core java  Hello sir,What is logic behinde the core java programms,How may programmas are there,for example,sorting of two numbers,grade of the student details,fibonice serice,paldroma,incremting of the program,asscedding
Core Java - Java Beginners
Core Java  What is Java? I am looking for Core Java Training  Hi friendThe Core Java Technologies and application programming interface...). They are used in all classes of Java programming, from desktop applications to Java EE
Core Java
Core Java  Hi, Can any one please expain me why derived data types are required in java as we have primitive data types with us
Core Java
Core Java  Hi, Can any one please expain me why derived data types are required in java as we have primitive data types with us
Core Java
Core Java  Hi, can any one please tell me the uses of return type,"Super" and "this" calling statement in Java?? why do we required this,super calling statement?? why return type is required
Core Java
Core Java  How to load class dynamically in java ?   To load class dynamically you can use Class class method Class.forName("abc.xyz.MyClass"); This method load the given class at run time
Core Java
Core Java  what is a class
Core Java
Core Java   How can i write own compile time and runtime exceptions in java   Hello Friend, Please visit the following links: http://www.roseindia.net/java/exceptions/how-to-throw-exceptions.shtml http
Core Java
Core Java  Is Java supports Multiple Inheritance? Then How ?   Hi Friend, Java does not support multiple inheritance but it can be achieved by using the interface. In Java, Multiple Inheritance can be achieved through
Core java
Core java  How to use hyperlink that is href tag in core java without swing, frames etc. My code is StringBuffer oBodyStringBuffer = new StringBuffer("Message Classification: Restricted.\n\n
Core Java Training Topics
of programming and working knowledge of computer. Core Java... Core Java Training Topics       Core Java Training Course Objective To teach 
CORE JAVA
CORE JAVA  What is called Aggregation and Composition
core java
core java  surch the word in the given file
Core Java
Core Java   Hi, Can any one please tell me the program to print the below matrix in a spiral order. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Thanks a lat in advance
core java
core java  I am having 10 countries in the data base as back end.in front end i am having a button in web page like SHOWCOUNTRIESLIST so i need java code how to retrive that 10 countries from back end to my page,,pls help me
core java
core java  how to write or update into excel file using...; Please visit the following links: http://www.roseindia.net/tutorial/java/poi/insertIntoExcelFileData.html http://www.roseindia.net/answers/viewqa/Java
core java - Java Beginners
core java  i want to get java projects in core java
Core java
Core java  difference between the string buffer and string builder
core java
core java  please give me following output
core java
core java  what is the use of iterator(hase next
Core Java
Core Java  can any one please tell me the difference between Static and dynamic loading in java???   The static class loading is done through the new operator while dynamic class loading is achieved through Run time
Core Java
Core Java  Is Java supports Multiple Inheritance? Then How ?   There is typo the question is , What is Marker Interface and where it can be used?   Hi Friend, An interface with no method is known as Marker
core java
core java  what does the term web container means exactly?please also give some examples   Hi, In Java Platform, Enterprise Edition specification, servlet container comes into picture. It is also know as web container
core java
core java  java program using transient variable   Hi Friend, A transient variable is a variable that may not be serialized.The transient..., visit the following link: http://www.roseindia.net/help/java/t/transient-java
Core java
Core java  how to convert reverse of String without using String function
core java
core java  Is it possible to create a shallow copy of an arraylist instance? if yes then please post the code
CORE JAVA
CORE JAVA  Tell me some Scenarios why you go for Abstract Class and Interface
core java
core java  Hi, Can any one please share a code to print the below: 1 121 12321 1234321
core java
core java  can i use native keyword with abstract method ? if yes explain and if no please explain
Core Java
Core Java  have to find the prime numbers which is less than the current prime numbers using loops
 

 

 

DMCA.com