Skip to main content

Posts

Showing posts from January, 2020

#Perfect Number Write a program of Perfect Number series in java languag...

Perfect Number ============================================================================================ 6 why becouse = 6%1==0-->true 1 1+2+3=6 6%2==0-->true 2 6%3==0-->true 3 6%4==0-->false * 6%5==0-->false * n= 4 why 4%1==0 true 1-> 1+2=3 4%2==0 true 2 4%3==0 false * //series of perfect Number import java.util.Scanner; class Perfect1{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int sum=0; for(int i=1;i<=n;i++){ sum=0; for(int j=1;j

#FibonacciNumberSeries Write a program of Fibonacci Number Series|| Fib...

Fibonacci Number Series ============================================ 0 1 1 2 3 5 8 13............. a=0; b=1; i=2; printf(a,b); while(i<=n){ c=a+b; printf(c); a=b; b=c; i++; } =========================================================================== import java.util.Scanner; class Fibonacci { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a=0,b=1,c; System.out.print(a+" "+b); for(int i=2;i<=n;i++){ c=a+b; System.out.print(" "+c); a=b; b=c; } } }

Objective Question in java written test Naresh It|| Hyderabad || java Objective Questions

                C-TEL INFOSYSTEM PVT LTD ================================================================= 1.pREDICT THE OUTPUT OF THE FOLLOWING JAVA PROGRAM.   class Testp  { public static void main(String[] args)  { String s1=new String("prince"); String s2=new String("prince"); if(s1==s2)    System.out.println("Equal"); else System.out.println("Not Equal"); } }  a. Equal   b.Not Equal    c.UncheckedException   d.none  Correct Ans:b.Not Eqaul -------------------------------------------------------------- 2.PREDICT THE OUTPUT OF THE FOLLOWING JAVA PROGRAM.  class super1 { final public int cal(int a,int b){       return 0; } } class sub1 extends super1 { public int cal(int a,int b){       return 1; } } class Testp  { public static void main(String[] args)  { sub1 a=new sub1(); System.out.println("X:"+a.cal(0,1));      } } a.CheckedException  b.UnCheckedException  c.

Java Interview Question || Top 10 question in java interview || by Er prince kumar

          Java Interview Question in java 1.1.Write a program     Take one n amount througth the user and distribute this amount     until amount will be zero/end. all amunt distribute in the run time    if amount is insufficent to the last user than display unsufficent    amount , avilable amount is 200 . Enter your amount 200 ok thanks ==================================== import java.util.Scanner; class ATMAmount{ public static void main(String args[]){     int amt; Scanner sc=new Scanner(System.in); System.out.print("Deposit Amount:"); amt=sc.nextInt(); int useramt=0; while(true){      System.out.print("Withdrawal Amount:");     useramt=sc.nextInt(); if(amt>=useramt){        amt=amt-useramt; } else if(amt<=0) {      System.out.println("Sorry..? Balance not Avilable "); break; } else{        System.out.println("Unsufficent Amunt \n Avilable Amt="+amt); }     

How to create custome exception in java || by Er prince kumar ojha

  How to create custome exception in java || by              Er prince kumar ojha   ==================================================================== This Java tutorial guides you on how to create your own exceptions in Java. In the article  Getting Started with Exception Handling in Java , you know how to catch throw and catch exceptions which are defined by JDK such as  IllegalArgumentException ,  IOException ,  NumberFormatException , etc. What if you want to throw your own exceptions? Imagine you’re writing a student management program and you want to throw  StudentException ,  StudentNotFoundException ,  StudentStoreException  and the like? So it’s time to create new exceptions of your own. We will call JDK’s exceptions  built-in exceptions  and call our own exceptions  custom exceptions . Let me tell you this: Writing custom exceptions in Java is very easy, but the important thing is, you should ask yourself this question:   1. Why do I need custom excepti