0% found this document useful (0 votes)
50 views2 pages

Contoh Program Java

The document contains the responses from a student named Putu Ari Sri Lestari Eka Ningsih to two programming assignments for an Object-Oriented Programming course. The first assignment asks the student to create a Java program to calculate y=ax+b. The student provides the source code and a screenshot. The second assignment again asks to calculate y=ax+b, with the added condition of checking if b=c and printing an error if true, else calculating and printing y. The student again provides the source code and a screenshot for the second program.

Uploaded by

arisrilestari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views2 pages

Contoh Program Java

The document contains the responses from a student named Putu Ari Sri Lestari Eka Ningsih to two programming assignments for an Object-Oriented Programming course. The first assignment asks the student to create a Java program to calculate y=ax+b. The student provides the source code and a screenshot. The second assignment again asks to calculate y=ax+b, with the added condition of checking if b=c and printing an error if true, else calculating and printing y. The student again provides the source code and a screenshot for the second program.

Uploaded by

arisrilestari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Nama

: Putu Ari Sri Lestari Eka Ningsih

NIM

: 1304505074

Kelas

:B

Mata Kuliah

: Pemrograman Berorientasi Obyek

1. Buatlah program untuk perhitungan y = ax + b dalam bahasa Java!


Jawab:
Source code program:
package Pertama;
import java.util.Scanner;
public class Pertama {
public static void main (String[] args){
Scanner input = new Scanner(System.in);

System.out.print("Masukan nilai a: ");


int a = input.nextInt();
System.out.print("Masukan nilai b: ");
int b = input.nextInt();
System.out.print("Masukan nilai x: ");
int x = input.nextInt();
int y = a * x + b;
}

System.out.println("Nilai y adalah: " +y);

Screen shoot program:

2. Buatlah program untuk perhitungan y = ax + b dalam bahasa Java!


Jawab:
Source code program:
package Tugas1;
import java.util.Scanner;
public class Tugas1 {
public static void main (String[] args){
Scanner masukan = new Scanner(System.in);
System.out.print("Masukan nilai b: ");
float b = masukan.nextFloat();
System.out.print("Masukan nilai c: ");
float c = masukan.nextFloat();
System.out.print("Masukan nilai x: ");
float x = masukan.nextFloat();

if (b == c) {
System.out.println("Maaf, perhitungan error");
}
else {
float y = x / (b - c);
System.out.println("Nilai y: " +y);
}
}

Screen shoot program:

You might also like