Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1st code
- import java.util.Scanner;
- public class MyClass {
- public static void main(String args[]) {
- int a=5;
- int b=5;
- try{
- System.out.println("Div = "+a/b);
- }
- catch(Exception e){
- e.printStackTrace();
- }
- finally{
- System.out.println("Done");
- }
- }
- }
- //2nd code
- import java.util.Scanner;
- public class MyClass {
- public static void main(String args[]) {
- Scanner usr = new Scanner(System.in);
- String s = usr.nextLine();
- try{
- System.out.println("1st char "+s.charAt(0));
- }
- catch(Exception e){
- System.out.println(e);
- }
- finally{
- System.out.println("Done");
- }
- }
- }
- //3rd code
- import java.util.Scanner;
- public class MyClass {
- public static void main(String args[]) {
- Scanner usr = new Scanner(System.in);
- String s = usr.nextLine();
- try{
- System.out.println("Char = "+s.charAt(100));
- }
- catch(Exception e){
- System.out.println(e);
- }
- finally{
- System.out.println("Done");
- }
- }
- }
- //4th code
- import java.util.Scanner;
- public class MyClass extends Exception{
- public MyClass(String str){
- super(str);
- }
- public static void main(String args[]) {
- Scanner usr = new Scanner(System.in);
- int value = usr.nextInt();
- int sum=0;
- try{
- if(value>1000)
- throw new MyClass("Sed laip");
- else
- {
- for(int i=1;i<=value;i++)
- sum+=i;
- System.out.println("Sum = "+sum);
- }
- }
- catch(Exception e){
- System.out.println(e);
- }
- finally{
- System.out.println("Done");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment