dElmARk Admin
Posts : 92 Join date : 09/04/2012
| Subject: BufferedReader Syntax Tue Oct 23, 2012 8:43 pm | |
| BufferedReader Syntax. The program starts with the code import java.io.*; before the class name, but must be inside the method - Code:
-
import java.io.*; class progName { public static void main(String[] args){ BufferedReader brVarName = new BufferedReader(new InputStreamReader(System.in))throws Exception; } }
| |
|
dElmARk Admin
Posts : 92 Join date : 09/04/2012
| Subject: Re: BufferedReader Syntax Tue Oct 23, 2012 8:44 pm | |
| Declaring variable together with its data type using BufferedReader. (Continued..) Via Input Data - Code:
-
String stringVar = brVarName.readLine(); char charVar = brVarName.readLine(); int intVar = Integer.parseInt(brVarName.readLine()); Double doubleVar = Double.parseDouble(brVarName.readLine()); Fload floatVar = Float.parseFloat(brVarName.readLine());
User Defined Declaration - Code:
-
String stringVar = "Text Message, Sencence or Paragraph"; char charVar = 'a'; || char charVar = '1'; int intVar = 12; Double doubleVar = 100.0; Fload floatVar = 50.0;
__________ Take a look at this: - Code:
-
import java.io.*; class Sample{ public static void main(String []args)throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Input Name: "); String name = br.readLine(); System.out.print("Input a letter or a number: "); char character = br.readLine(); System.out.print("Input your age: "); int age = Integer.parseInt(br.readLine()); System.out.print("Input a number with decimal: "); Double Doubledecimal = Double.parseDouble(br.readLine()); System.out.print("Input a number with decimal: "); Fload Floatdecimal = Float.parseFloat(br.readLine()); } }
| |
|