Csharp
using System; namespace OOPpraktikum { class Program { public static void Main(string[] args) { int angka; try { Console.Write("Masukkan Angka = "); angka = Convert.ToInt32(Console.ReadLine()); } catch(Exception) { Console.WriteLine("Input Pake Angka . . bukan Huruf . . ."); } Console.Write("\nPress any key to continue . . . "); Console.ReadKey(true); } } }
Java
package OOPpraktikum; import java.util.*; public class MainClass { static Scanner input = new Scanner(System.in); public static void main(String[] args) { int angka; try { System.out.print("Masukkan Angka = "); angka = input.nextInt(); } catch(Exception e) { System.out.println("Input Pake Angka . . bukan Huruf . . ."); } System.out.println("\nPress any key to continue . . . "); } }
C++
#include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { try { int i; cout<<"Masukkan Angka = "; if(!(cin>>i)) { throw i; } } catch(int e) { cout<<"Input Pake Angka . . . Bukan Huruf . ."<<endl; } cout<<endl; system("PAUSE"); return EXIT_SUCCESS; }
No comments:
Post a Comment