import java.util.*; public class tanggal { public static void main(String [] args) { Scanner scan=new Scanner(System.in); int tanggal=0; String bulan=""; System.out.print("Tanggal:"); tanggal=scan.nextInt();scan.nextLine(); System.out.print("Bulan:"); bulan=scan.nextLine(); if(bulan.equals("Feb")&&tanggal>28) { System.out.println("Input invalid"); tanggal=0; } else if(bulan.equals("Jan")&&bulan.equals("Maret")&&bulan.equals("Mey")&&bulan.equals("Juli")&&bulan.equals("Agustus")&&bulan.equals("Oktober")&&bulan.equals("Desember")||tanggal>31) { System.out.println("Input invalid"); tanggal=0; } else if(bulan.equals("April")&&bulan.equals("Juni")&&bulan.equals("September")&&bulan.equals("November")||tanggal>30) { System.out.println("Input invalid"); tanggal=0; } else { System.out.println("Input invalid"); tanggal=0; } } }
bool valid = false; while (!valid) { valid = true; //Do your stuff here and set 'valid' to false when it becomes invalid, //probably starting with your "String bulan="";" line //... }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)