Memberi Spasi Pada Kalimat
import java.io.*;
class kataspasi {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Masukkan Kalimat : ");
String a;
a=br.readLine();
for(int i=0;i<a.length();i++){
System.out.print(a.charAt(i)+" ");
}
}
}
Hitung Kata
import java.io.*;
class htungkata{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Masukkan Kalimat : ");
String a;
int c=1;
a=br.readLine();
char [] b = new char [a.length()];
b=a.toCharArray();
for(int i=0;i<a.length();i++){
if (b[i]==' '){
c=c+1;
}
}
System.out.println();
System.out.println("Kata = "+c);
}
}
Hitung Deret 0,1,3,6,9.....n
import java.io.*;
class cetakderet{
public static void main(String[] args) throws IOException{
System.out.print("Masukkan batas deret = ");
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String a;
int N = 0;
int bil=0,cacah=1;
a=br.readLine();
try{
N=Integer.parseInt(a);
while(bil<=N){
System.out.print(bil+" ");
bil=bil+cacah;
cacah++;}
}catch(NumberFormatException nfe){
System.exit(0);
}
}
}
Deret pertambahan 1+2+3+4...n
import java.io.*;
class programtambah{
public static void main(String[] args) throws IOException
{
System.out.print("Masukkan bilangan:");
String temp;
int hasil=0;
int bil;
int i=1;
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
temp = br.readLine();
try{
bil=Integer.parseInt(temp);
while(i<=bil){
System.out.print(i);
if(i!=bil){
System.out.print("+");
}
else{
System.out.print("=");
}
hasil+=i;
i++;
}
System.out.println(hasil);
}
catch(NumberFormatException nfe){
System.exit(1);
}
}
}
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar