Anda di halaman 1dari 9

Tugas Pemrogaman Java

Oleh :

Dewa Gede Dede Pramana

NIM : 1104405048

JURUSAN TEKNIK ELEKTRO

FAKULTAS TEKNIK UNIVERSITAS UDAYANA

BUKIT JIMBARAN

2014
Tugas 1a :

Psedocode:

s=br.readLine();
s= +s;
s=s.toUpperCase();

l=s.length();

for(int i=0;i< panjang kalimat)

if(x==' ')

s.charAt(i+1)+"."

Out(initialname)

end
Flowchart Initial Name:

start

String s;
char x;
int l;

"Enter any
sentence: "

s=br.readLine();
s= +s;
s=s.toUpperCase();
l=s.length();

false

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

true if(x==' ')

s.charAt(i+1)+"."

Out(initial)

end
Source code Initial Name :

/**

* @author dewadede

*/

import java.io.*;

public class InitialsName

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

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

String s;

char x;

int l;

System.out.print("Enter any sentence: ");

s=br.readLine();

s=" "+s; //adding a space infront of the inputted sentence or a name

s=s.toUpperCase(); //converting the sentence into Upper Case (Capital Letters)

l=s.length(); //finding the length of the sentence</span>

System.out.print("Output = ");

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

{
x=s.charAt(i); //taking out one character at a time from the sentence

if(x==' ') //jika setelah kata terdapat spasi maka print out karakter selanjutnya
hingga berhenti

System.out.print(s.charAt(i+1)+" ");

}
Tugas 1b:

Psedocode::

n = save.nextLine();

n = n.replaceAll("[-,'',:,;,!,?,',.,]", " ");

String []kata = n.split(" ");

for(i=0; i<panjang kalimat; i++){

out(kata[i]);

end
Flowchart kalimat:

start

String n;
int i;

"Masukan
kalimat anda :"

n = save.nextLine();
n = n.replaceAll("[-,'',:,!,?,',.,,]", " ");

False

for(i=0; )

true i++

kata.length

Out(kata)

end
Source code kalimat :

/**

* @author dewadede

*/

import java.util.Scanner;

public class Kalimatlanjut {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

Scanner save = new Scanner (System.in);// memindai data inputan

//variable

String n; // mendeskripsikan string sebagai input

int i;

//

System.out.print ("Masukan kalimat kamu :");

n = save.nextLine(); // menyimpan inputan kalimat dan melanjutkan ke kata setelah


spasi

n = n.replaceAll("[-,'',:,;,!,?,',.,]", " ");


String []kata = n.split(" ");

for(i=0; i<kata.length; i++){

System.out.println(kata[i]);