Thursday, 23 August 2018

Contoh Script Java Buffered Reader input angka dan input kata


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class quiz
{
                public static void main(String[]args)
                {
                                BufferedReader dataIn=new BufferedReader(new InputStreamReader(System.in));
                                try
                                {
                                                System.out.print("input kata: ");
                                                String input=dataIn.readLine();
                                                String strOrig=input;
                                                System.out.print("masukkan bagian kata yang ingin dicari(pencarian case
                                           sensitive):");
                                                String search =dataIn.readLine();
                                                int intIndex=strOrig.indexOf(search);
                                                if(intIndex== -1)
                                                {
                                                                System.out.println("Pencarian tidak bisa ditemukan");
                                                }
                                                                else
                                                {
                                                                System.out.println("Kata tersebut telah ditemukan pada index ke-" + \

                                            intIndex);
                                                }
                                                }
                                                catch(IOException e)
                                                {
                                                                System.out.println("Error");
                                }                             
                }
}



Contoh Input Angka :

import java.io.*;

public class quiz2
{
                public static void main(String[]args)throws Exception
                {
                                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                                int DataArray[]= {3, 6, 19, 90, 30, 20, 10, 8};
                                int x, NilaiX;
                                boolean Ketemu;
                               
                                //Menampilkan nilai data array
                                System.out.println("\nData Array:");
                                for(x=0; x<=DataArray.length-1; x++)
                                {
                                                System.out.print(DataArray[x]+" ");
                                }
                                System.out.println("\n");
                                //Masukkan data yang dicari
                                System.out.print("Masukkan angka yang dicari: ");
                                String Input=br.readLine();
                                NilaiX=Integer.parseInt(Input);
                                Ketemu=false;
                                for(x=0; x<=DataArray.length-1; x++)
                                {
                                                if(DataArray[x]==NilaiX)
                                                {
                                                                Ketemu=true;
                                                                break;
                                                }
                                }
                                if(Ketemu==true)
                                {
                                                System.out.println("Angka"+NilaiX+"ditemukan pada Index Array ke-"+(x+1)+"\n");
                                }
                                else
                                {
                                                System.out.println("Angka tidak ditemukan\n");
                                }
                }
}

Download script disini

No comments:

Post a Comment