Showing posts with label number. Show all posts
Showing posts with label number. Show all posts
Java determine prime number
Read floating point number user input in java
Complete source code below, will show you how to wait and read floating point number user input in command prompt.
********************************************************************
COMPLETE SOURCE CODE FOR : ReadFloatingPointNumberUserInput.java
********************************************************************
********************************************************************
JUST COMPILE AND EXECUTE IT
********************************************************************
********************************************************************
COMPLETE SOURCE CODE FOR : ReadFloatingPointNumberUserInput.java
********************************************************************
import java.util.Scanner;
public class ReadFloatingPointNumberUserInput
{
public static void main(String[]args)
{
try
{
//Create a scanner object
//Scanner is a predefined class in java that will be use to scan text
//System.in is mean, we will receive input from standard input stream
Scanner readUserInput=new Scanner(System.in);
//Print into command prompt(Put a floating point number : )
System.out.print("Put a floating point number : ");
//Wait and READ FLOATING POINT NUMBER from user input after user hit 'Enter'
float myPointNumber=readUserInput.nextFloat();
//Print what store in myPointNumber
System.out.println("My floating point number is : "+myPointNumber);
}
catch(Exception exception)
{
//Error that will be print if user put other than floating point number
System.out.println("Hey !!! Don't put other than floating point number");
}
}
}
********************************************************************
JUST COMPILE AND EXECUTE IT
********************************************************************
Get numbers of character in a string
Complete source code below will show you, how to get numbers of character that contain in a String. If you compile and execute source code below, you will get numbers of character is equal to 15 not 14. This is because the whitespace in a String also count.
***********************************************************************
COMPLETE SOURCE CODE FOR : GetNumbersOfCharacterInAString.java
***********************************************************************
***********************************************************************
JUST COMPILE AND EXECUTE IT
***********************************************************************
***********************************************************************
COMPLETE SOURCE CODE FOR : GetNumbersOfCharacterInAString.java
***********************************************************************
public class GetNumbersOfCharacterInAString
{
public static void main(String[]args)
{
//Create a String
//You can change to other String that you want
String a="Hello everybody";
//Get numbers of character in created String and store it in int variable
int numbersOfCharacter=a.length();
//Print result
System.out.println("Numbers of character is : "+numbersOfCharacter);
}
}
***********************************************************************
JUST COMPILE AND EXECUTE IT
***********************************************************************
Get number of screen
Subscribe to:
Posts (Atom)