Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

package hitungtxt;

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.io.PrintWriter;

import java.util.Scanner;

public class Hitungtxt

public static void main(String[] args) throws IOException

Scanner x = new Scanner (System.in);

String n;

int jml=0;

int angka;

System.out.print("Masukan Banyak angka : ");n=x.nextLine();

int b=Integer.parseInt(n);

FileWriter fw = new FileWriter("angka.txt",true);

PrintWriter pw = new PrintWriter(fw);

for(int i=0;i<b;i++)

{
System.out.print("Masukan Angka : ");angka=x.nextInt();

pw.println(angka);

pw.close();//untuk save

//BACA

FileReader fr = new FileReader("angka.txt");

BufferedReader br = new BufferedReader(fr);

String s = br.readLine();//baca satu baris

while(s!=null)

System.out.println(s);

jml=+Integer.parseInt(s);

s=br.readLine();

System.out.print("Jumlah : "+jml);

You might also like