Postingan lainnya
Cannot return a value from a method with void result type
Hallo semua, maaf saya newbie. Sebelumnya saya sudah belajar beberapa programming language seperti python dan C++. Dan saat ini saya sedang ngambil kursus dasar pemrogramman java (dapet prakerja) soalnya kelas pythonnya penuh :(, nah ini saya pnya program kayak gini:
import java.util.*;
public class Second {
public static void main(String[] args){
char[] driver = {'A', 'B', 'C', 'D', 'E'};
String alamatJemput = "Jakarta Pusat";
String alamatAntar = "Jakarta Pusat";
int jarak = 20;
int harga = 60000;
Scanner answerInp = new Scanner(System.in);
int answerInd = 0;
int n = 0;
char driverIn = driver[n];
while(answerInd == 0){
System.out.println("Halo Driver " + driverIn);
System.out.print("Alamat Jamput \t : " + alamatJemput);
System.out.println("Alamat Antar \t : " + alamatAntar);
System.out.println("Jarak \t : " + jarak + " KM");
System.out.println("Harga \t : Rp. " + harga);
System.out.println("Ketik 'Y' jika terima order, atau 'N' untuk menolak order : ");
char answer = answerInp.next().charAt(0);
if(answer == 'Y' | answer == 'Y') {
answerInd = answerInd + 1;
n = n+1;
return n;
}
}
System.out.println("========== ORDERAN DITERIMA ==========");
System.out.println("Halo Driver " + driverIn);
System.out.print("Alamat Jamput \t : " + alamatJemput + "\n");
System.out.println("Alamat Antar \t : " + alamatAntar +"\n");
System.out.println("Jarak \t : " + jarak + " KM\n");
System.out.println("Harga \t : Rp. " + harga +"\n");
}
}
nah tapi perintah returnnya ga bisa dan tertulis cannot return a value from a method with void result type bisa minta tolong solusinya suhu, buat tugas kursusnya soalnya thank youu.
saya ingin hasilnya kayak gini:
Halo Driver A
Alamat Jemput : Jakarta PusatAlamat Antar : Jakarta Pusat
Jarak : 20 KM
Harga : Rp. 60000
Ketik 'Y' jika terima order, atau 'N' untuk menolak order : N
Halo Driver B
Alamat Jemput : Jakarta Pusat
Alamat Antar : Jakarta Pusat
Jarak : 20 KM
Harga : Rp. 60000
Ketik 'Y' jika terima order, atau 'N' untuk menolak order :
Y
========== ORDERAN DITERIMA ==========
Halo Driver B
Alamat Jamput : Jakarta Pusat
Alamat Antar : Jakarta Pusat
Jarak : 20 KM
Harga : Rp. 60000
Process finished with exit code 0
2 Jawaban:
<div><a href="https://www.gethotcontent.com/seo">seo business</a><br><br>Time is like a sharp It can carve hard lines on beautiful faces and wear out youth year after year, but using it well can make a piece of simple stone into a great statue. St. Mary Academy is still a simple piece of white stone briefly carved, but as time marches on, com it may be spoiled by dust, worn out by weather, or broken into separate pieces. It may be also carefully carved by knife into wonderful statues. Everyone at school, including our schoolmates, controls this knife.</div>
<pre>public static void main</pre><div>itu emang ga bisa ngasih return nilai, karena berbentuk void<br>kalau memang mau mengeluarkan nilai return harus ganti dengan tipe data yang sama sesuai yang akan di return misal int</div><pre>public static int main</pre>