Soal latihan java. Soal 1 public class MyClass { public static void main() { int arrmul [] [] = new int [4] [5]; int k = 0; for (int i=0;i<4;i++){ for.

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

Classes And Objects II. Recall the LightSwitch Class class LightSwitch { boolean on = true; boolean isOn() { return on; } void switch() { on = !on; }
Control Structures.
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
1 Classes and Objects in Java Parameter Passing, Delegation, Visibility Control, and Object Cleanup.
Lecture 4 More on Java® Data Types, Control Structures.
Iterations for loop. Outcome Introduction to for loop The use of for loop instead of while loop Nested for loops.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Methods and Formatted Output Chapter 4. Overview Breaking down a big program into small methods. Formatting output – using printf – using DecimalFormat.
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice.
1 Todays Objectives Announcements Homework #1 is due next week Return Quiz 1 – answers are posted on the Yahoo discussion page site Basic Java Programming.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Copyright © Recursive GCD Demo public class.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
1 Arrays An array is a special kind of object that is used to store a collection of data. The data stored in an array must all be of the same type, whether.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Computer Programming Lab(7).
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
Chapter 10 Ch 1 – Introduction to Computers and Java Streams and File IO 1.
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Question from the last class What happens if we cast “too large” float/double to an int? int has range float a=1e10f; int b=(int)
1 Calling within Static method /* We can call a non static method from a static method but by only through an object of that class. */ class Test1{ public.
Objects contains data and methods Class – type of object Create class first Then object or instance String – defined class String s; // creates instance.
Craps. /* * file : Craps.java * file : Craps.java * author: george j. grevera, ph.d. * author: george j. grevera, ph.d. * desc. : program to simulate.
Hand Trace and Output for: int digit = 0; int number = 1423; do { digit = number % 10; System.out.println(digit); number = number / 10; } while (number.
CS110 Programming Language I
Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
Discussion1 Quiz. Q1 Which of the following are invalid Java identifiers (variable names)? a) if b) n4m3 c) Java d) e) DEFAULT_VALUE f) bad-choice.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.1 Chapter 3 Selections.
Computer Programming Lab 8.
Övning 4. Repetition göra egna klasser class Rektangel { private double längd; private double bredd; public Rektangel(double l, double b) { this.längd.
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
1 More on Decisions Overview l The selection Operator l Grouping of Statements l Multiple branches (if else if) l Switch Statement.
Chapter 3 Control Statements F Selection Statements –Using if and if...else –Nested if Statements –Using switch Statements –Conditional Operator F Repetition.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Control Structures A control structure is simply a pattern for controlling the flow of a program module. The three fundamental control structures of a.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
Miscellaneous topics Chapter 2 Savitch. Miscellaneous topics Standard output using System.out Input using Scanner class.
OOP (pre) Basic Programming. Writing to Screen print will display the string to the screen, the following print statement will be appended to the previous.
More loops while and do-while. Recall the for loop in general for (initialization; boolean_expression; update) { }
int num = 22; if (num > 0) if (num % 5 == 0) System.out.println(num); else System.out.println(num + “ is negative”);
Chapter One Lesson Three DATA TYPES ©
A: A: double “4” A: “34” 4.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Switch Statement.
Programming – Lecture 15 Going Beyond the ACM Library.
OPERATOR Dalam Java.
CSC111 Quick Revision.
AKA the birth, life, and death of variables.
using System; namespace Demo01 { class Program
Sum of natural numbers class SumOfNaturalNumbers {
Control Statement Examples
Review Operation Bingo
null, true, and false are also reserved.
TO COMPLETE THE FOLLOWING:
محاضرة 1: مقدمة للمسـاق و مراجعـة للأساسيـات
Interfaces and Constructors
Recursive GCD Demo public class Euclid {
AKA the birth, life, and death of variables.
class PrintOnetoTen { public static void main(String args[]) {
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Module 2 - Part 1 Variables, Assignment, and Data Types
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Module 3 Selection Structures 4/5/2019 CSE 1321 Module 3.
Agenda Types and identifiers Practice Assignment Keywords in Java
Presentation transcript:

Soal latihan java

Soal 1 public class MyClass { public static void main() { int arrmul [] [] = new int [4] [5]; int k = 0; for (int i=0;i<4;i++){ for (int j=0;j<5;j++) { arrmul [i] [j] = k++; } for (int i=0;i<4;i++){ for (int j=0;j<5;j++) { System.out.print(arrmul [i] [j] + " "); } System.out.println(); } }

Soal 2 class TestContinue7 { public static void main(String[] args) { int x=10,y; label1: while(x-->0) { y=0; while(y++<10) { if(y > x) { System.out.println(); continue label1; } System.out.print(x*y + " "); }

Soal 3 public class grade6 { public static void main (String[] arf) { outerLoop: for (int i=0;i<5;i++) { for (int j=0;j<5;j++) { System.out.println("Inside for (j) loop"); if (j==2) continue outerLoop; } System.out.println("Inside for (i) loop"); }

Soal 4 import javax.swing.*; public class bintang { public static void main (String[] args) { int baris; baris=Integer.valueOf(JOptionPane.showInputDialog("Masukkan banyak bintang ?")); for (int i=1;i<=baris;i++) { for (int j=1;j<=baris;j++) { if (i<=j) System.out.print("*"); else System.out.print(" "); } System.out.println(); }

Soal 5 public class MyClass { public static void main() { int x =7; System.out.println("x = "+ x); System.out.println("x >> 2 = " + (x >>2)); System.out.println("x << 2 = " + (x <<2)); System.out.println("x >>> 1 = " + (x >>> 1)); }

Soal 6 class TestIter5 { public static void main(String[] args) { int g,h; System.out.println("Sebelum for"); for(g=0,h=6;g =3;g++,h--) { System.out.println("Nilai g : " + g); System.out.println("Nilai h : " + h); } System.out.println("Setelah for"); }

Soal 7 public class coba2 public static void main (String[] args) { int i,j; for(i=0;i<2;i++) { for(j=0;j<3;j++) { if (i==j) { continue; } System.out.println("i="+i+"j="+j); }

Soal 8 class Operator9{ public static void main(String[] args) { int x,hasil; x = 40; boolean test1 = true; hasil = test1?x/10:x*20; System.out.println("Nilai x : "+ x); System.out.println("Nilai Hasil : "+ hasil); }

Soal 9 class Operator8{ public static void main(String[] args) { int x,y; x=10; y=5; if(x>y & ++x>10) { System.out.println("TRUE 3 x : " + x); System.out.println("TRUE 3 y : " + y); System.out.println("TRUE 3 : "); }else { System.out.println("FALSE 3"); }

Soal 10 class Operator5{ public static void main(String[] args) { int x,y; x = 5; if(x!=0 && (x/2)>=5){ System.out.println("TRUE 1 : " + x); System.out.println("TRUE 1 : "); }else { System.out.println("FALSE 1"); } }

Soal 11 public class sk3 { public static void main (String[] args) { int i=0, j=2; do { i=++i; j--; } while (j>0); System.out.println(i); }

Soal 12 class LitIntFloat { public static void main(String[] args) { int okt1 = 056; int hek1 = 0xc; System.out.println("Nilai Oktal : " + (int) okt1); System.out.println("Nilai Heksa 1 : " + (int) hek1); }

Soal 13 class TestIter8 { public static void main(String[] args) { int a = 0 ; System.out.println("Sebelum while"); while(a>0) { System.out.println("Nilai a : "+a); a--; } System.out.println("Setelah while"); }

Soal 14 class Example { static void main() { int input = Input.readInt(); double real = 20; int i = 0; while ( real > input) { real = real * 0.4; i = i + 1; Output.println(i); }

Soal 15 class TestSwitch3 { public static void main(String[] args) 5 int bulan = 4; switch(bulan) { case 1: System.out.println("pertama"); case 2: System.out.println("kedua"); case 3: System.out.println("kuartal 1"); break; case 4: case 5: System.out.println("kelima"); break; case 6: System.out.println("kuartal 2"); break; case 7: case 8: case 9: System.out.println("kuartal 3"); break; default: System.out.println("kuartal 4"); } System.out.println("keluar dari switch"); }

Soal 16 class TestContinue6 { public static void main(String[] args) { int x=10; System.out.println("Sebelum while"); while(x-->1) { if(x % 2 == 0) continue; System.out.println("Nilai x : " + x); } System.out.println("Sesudah while"); }

Soal 17 class TestSeleksi1 { public static void main(String[] args) { int a,b; a = 10; b = a/2; if(b>5) System.out.println("Pernyataan1 Test Seleksi 1 dieksekusi"); else System.out.println("Pernyataan2 Test Seleksi 1 dieksekusi"); System.out.println("Pernyataan3 Test Seleksi 1 dieksekusi"); }