0% found this document useful (0 votes)
33 views6 pages

Contekan

The document contains code snippets from various Java packages and classes that demonstrate different Java concepts like variables, loops, conditionals, methods, and input/output. The code examples show how to use concepts like for loops, if/else statements, break/continue, variables, and taking user input to perform calculations and display output.

Uploaded by

Angga Aditya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views6 pages

Contekan

The document contains code snippets from various Java packages and classes that demonstrate different Java concepts like variables, loops, conditionals, methods, and input/output. The code examples show how to use concepts like for loops, if/else statements, break/continue, variables, and taking user input to perform calculations and display output.

Uploaded by

Angga Aditya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

package buffered;

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

public class lathanbuffered { public static void main(Strin !" ar s# thro$s IOException { BufferedReader br % ne$ BufferedReader(ne$ InputStreamReader(S&stem.in##; Strin nama % null; Strin stra$al % null; Strin strbun a % null; Strin strperiode % null; tr& { S&stem.out.print('masu((an nama anda) '#; nama % br.read*ine(#; S&stem.out.print('masu((an jumlah a$al investasi (Rp#) '#; stra$al % br.read*ine(#; S&stem.out.print('masu((an bun a (mis +.,%,+-#) '#; strbun a%br.read*ine(#; S&stem.out.print('masu((an periode) '#; strperiode % br.read*ine(#; . catch(IOException ioe#{ S&stem.out.println('/esalahan IO pada saat menan&a(an nama anda'#; S&stem.exit(,#; . double a$al; double bun a;int periode;double a(hir; periode%Inte er.parseInt(strperiode#; a$al% 0ouble.parse0ouble(stra$al#; bun a% 0ouble.parse0ouble(strbun a#; a(hir%a$al 12ath.po$(,3bun a4periode#;

S&stem.out.println(#; S&stem.out.println('terima (asih4' 3 nama#; S&stem.out.print('hasil investasi anda setelah ' 3 periode 3 'tahun'#; S&stem.out.println('adalah Rp ' 3a(hir#;

. .

package perulangan.bintang;
public class perulan anbintan {

public static void main(Strin !" ar s# { int i4x; for (i%,;i5%,6;i33# { for(x%,;x5%i;x33#

{ S&stem.out.print(717#; . S&stem.out.println(78n7#; . .

package variabel;
public class latihanvariabel {

static int a%6; private static Strin &; public static void main(Strin !" ar s# { int x; x%,+; S&stem.out.println('nilai a3x %'3(a3x##; { int &; &%9; S&stem.out.println('nilai a3x3&% '3(a3x3&##; int :; :%6+; S&stem.out.println('nilai a3x3&3:% '3(a3x3&3:##; . S&stem.out.println('nilai &% '3(&##; . .

package lanjutanoperating;
public class operatin { public static void main (Strin !" ar s# { int !" arr%ne$ int !9"; for (int i%+;i5arr.len th;i33#{ S&stem.out.println (';ilai i )'3i#; arr!i"%i; . for (int isiarr ) arr#{ S&stem.out.println ('Isi arra& )'3isiarr#; . .

package operator;
public class operator, { public static void main(Strin !" ar s# {

int x%,+; int &; & % 33x; S&stem.out.println(&#; . .

package Lingkaran1;
import java.util.1; public class *in (aran, { public static void main(Strin !" ar s# {

float phi % 66<=4 jari64luas;

Scanner inputpro ram % ne$ Scanner (S&stem.in#; S&stem.out.print('2asu((an jari6 lin (aran ) '#; jari6 % inputpro ram.next>loat(#; luas % jari6 1 jari6 1 66<=; S&stem.out.print('*uas lin (aran tersebut adalah) ' 3 luas#; . .

<1 1 ?o chan e this template4 choose ?ools @ ?emplates 1 and open the template in the editor. 1<

package testbreak1;
public class testbrea(, { public static void main (Strin !" ar s# { for (int n%,;n59;n33# { S&stem.out.println ('Aerulan an for (eB'3n#;

for (int m%+;m5,+;m33# { if (m%%9# brea(; S&stem.out.println (';ilai m )'3m#; . . S&stem.out.println ('8nSetelah for'#; . .

package testbreak3;
public class testbrea(C { public static void main(Strin !" ar s# { S&stem.out.println ('Sebelum for'#; labela) for (int (%6;(5,+;(%(36#{ S&stem.out.println ('Aerulan an ;ilai ( )'3(#; .<<blo( code label a label,) for (int x%,;x5,+;x33#{ S&stem.out.println ('Aerulan an ;ilai x )'3x#; label6) for (int &%9;&D%,;&BB#{ if (x%%C# S&stem.out.println ('8n;ilai & )'3&#; testbrea(C labela; .<<a(hir dari blo( label6 .<<a(hir blo( label, S&stem.out.println ('Setelah for'#; .<<E(hir method .

package testcontinue1;
public class ?estFontinue, { public static void main(Strin !" ar s# {

int x % ,+; S&stem.out.println ('sebelum $hile'#; $hile (xBBD,# { if (x - 6%%+# continue; S&stem.out.println (';ilai x )'3x#; . S&stem.out.println ('Setelah $hile'#; .

package testseleksi2;
public class ?estSele(si6 { public static void main(Strin !" ar s# { int x % ,+4&; label, ) $hile (xBBD+#{ &%+; $hile (&335,+# { if (& D x# { S&stem.out.println(#; continue label,; . S&stem.out.print( '1'#; . . .

You might also like