twitter

Monday, October 24, 2011

Java Programming Chapter 4 (Bigger Number)

Ok in this chapter i will share how to find the bigger number with use Java Input Output Buffered Reader check this code :
import java.io.*;
public class BiggerNum{
 public static void main(String[] args){
  BufferedReader inputnum = new BufferedReader(new InputStreamReader(System.in));
  String i="";
  int temp=0;
  for(int j=1; j<=3; j++){
   System.out.print("Input to"+j+" : ");
   try {
    i = inputnum.readLine();
   }catch(IOException e){
    System.out.println("data error!!!");
   }
   int input= Integer.parseInt(i);
  if (temp<input){
   temp=input;
   } 
  }
  
  System.out.println("Bigger number is : "+temp);
 }
}


  1. import java.io.*;
    That code will import java Input Output used Buffered Reader and Stream Reader
  2. BufferedReader inputnum = new BufferedReader(new InputStreamReader(System.in));
    That code will defined inputnum for variable BufferedReader and will be use for input state
  3. int input= Integer.parseInt(i);
    That code will defined input is new variable and "Integer.parseInt" used for convert String variable to integer variable.
  4. if statement will selection if input bigger than temp so temp content is same with input content.
  5. See ya in the next chapter... :D       ^_^v

No comments:

Post a Comment