Input and output

System.out.println("Some text");
System.out.println(myint);

Reading from input using Scanner

import java.util.*;
...
    Scanner sc=new Scanner(System.in);
    int a = sc.nextInt();

    while(sc.hasNextInt()){
        int a=sc.nextInt();
        System.out.println(a);
    }

Using Scanner

  • to read int: sc.nextInt()
  • to read double: sc.nextDouble()
  • to read String: sc.nextLine() or sc.next()

Formatting the output: System.out.format("", ..)

#