alexa-tracking

Main Content

1024
1024
KASKUS
51
244
https://www.kaskus.co.id/thread/5305cc78118b460b578b46c9/nanya-java-donk-sepuh2
nanya java donk sepuh2
kenapa ga bisa masuk ke invalid number ya gan?

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


public class Lat42 {
static int number[] = {1,2,3,4,5,6,7,8,9,10};
//static int number = 1;
static boolean cekinput = false;
static int Hinput;

public static void getInput(){
Scanner input = new Scanner(System.in);
Hinput = input.nextInt();
}


public static void checkNumber(){
for(int i =0 ; i<10 ; i++){
if(number[i]==(Hinput)){
cekinput=true;
// System.out.println("you typed: " +Hinput);
break;
}

}

if (cekinput=true){
System.out.println("you typed: " +Hinput);
}else{
System.out.println("invalid number");
}
}


public static void main (String args[]){
System.out.println("please input between 1 to 10: ");
Lat42.getInput();
Lat42.checkNumber();
}


}
wedew dopost... kok jadi amburadul O_o
coba baca baca disini
Code:
http://www.dreamincode.net/forums/topic/75696-meaning-of-import-static-javalangsystemout%3B/
bukan masalah itu gan...

result nya begini


Room number: 5
How many guests? 4

Do another? Exception in thread "main" java.lang.NullPointerException
at Guest.main(Guest.java:22)

Process completed.
Quote:Original Posted By SENSOR
misi sepuh2, ini kenapa selalu nullpointerexception ya? mohon pencerahan

import java.util.Scanner;
import static java.lang.System.out;

class Guest {
public static void main(String args[]) {
Scanner myScanner = new Scanner (System.in);
int whichRoom, numGuest;
int guestIn[];
guestIn = new int [10];

for (int roomNum = 0 ; roomNum < 10 ; roomNum++ ) {
guestIn[roomNum]=0;
}

do {
out.print("Room number: ");
whichRoom = myScanner.nextInt();
out.print("How many guests? ");
numGuest = myScanner.nextInt();
guestIn[whichRoom] = numGuest;
out.println();
out.print("Do another? ");
}while (myScanner.findInLine(".").charAt(0) == 'Y');

out.println();
out.println("Room\tGuest");
for (int roomNum = 0 ; roomNum < 10; roomNum++){
out.print(roomNum);
out.print("\t");
out.print(guestIn[roomNum]);
}
}
}


null pointer disini gan
Code:
myScanner.findInLine(".")

findInLine nya ngapain nyari "." (titik) gan? emang agan maunya nginput "Y." ya?
langsung aja dicek inputannya
Quote:Original Posted By agusinting


null pointer disini gan
Code:
myScanner.findInLine(".")

findInLine nya ngapain nyari "." (titik) gan? emang agan maunya nginput "Y." ya?
langsung aja dicek inputannya


hmm.. mau nyari yang terakhir diinput keyboard gan, kalo Y ulang lagi masukin angka... kalo N keluarin history yang kita input
Quote:Original Posted By SENSOR


hmm.. mau nyari yang terakhir diinput keyboard gan, kalo Y ulang lagi masukin angka... kalo N keluarin history yang kita input


ganti aja line itu jadi gini
Code:
myScanner.next().compareTo ("Y")==0
Quote:Original Posted By agusinting


ganti aja line itu jadi gini
Code:
myScanner.next().compareTo ("Y")==0


emoticon-Matabelo bener juga gan, thank you emoticon-Shakehand2
Quote:Original Posted By SENSOR
emoticon-Matabelo bener juga gan, thank you emoticon-Shakehand2

sama2 gan emoticon-Shakehand2

emoticon-Rate 5 Star emoticon-Blue Guy Cendol (L)
sundul pertanyaan baru masta2, mohon pencerahan emoticon-Matabelo
emoticon-Sundul Gan (S)
kalo mo nanya, mending dilanjutin post-nya
jangan edit post yg udah ada.
jadi bingung gw ikutin thread ini emoticon-Bingung (S)
Quote:Original Posted By pekoy154
kalo mo nanya, mending dilanjutin post-nya
jangan edit post yg udah ada.
jadi bingung gw ikutin thread ini emoticon-Bingung (S)

iya mas gan

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


public class Lat42 {
static int number[] = {1,2,3,4,5,6,7,8,9,10};
//static int number = 1;
static boolean cekinput = false;
static int Hinput;

public static void getInput(){
Scanner input = new Scanner(System.in);
Hinput = input.nextInt();
}


public static void checkNumber(){
for(int i =0 ; i<10 ; i++){
if(number[i]==(Hinput)){
cekinput=true;
// System.out.println("you typed: " +Hinput);
break;
}

}

if (cekinput=true){
System.out.println("you typed: " +Hinput);
}else{
System.out.println("invalid number");
}
}


public static void main (String args[]){
System.out.println("please input between 1 to 10: ");
Lat42.getInput();
Lat42.checkNumber();
}


}
kenapa ga mauk ke invalid number ya?
sundul gan