Top 10 Java Questions Problems

Top 10 Java Questions Problems
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Top 10 Java Questions Problems

1.A certain grade of steel is graded according to the following conditions:

(i) Hardness must be greater than 50

(ii) Carbon content must be less than 0.7

(iii) Tensile strength must be greater than 5600

The grades are as follows:

Grade is 10 if all three conditions are met

Grade is 9 if conditions (i) and (ii) are met

Grade is 8 if conditions (ii) and (iii) are met

Grade is 7 if conditions (i) and (iii) are met

Grade is 6 if only one condition is met

Grade is 5 if none of the conditions are met

Write a program, which will require the user to give values of hardness, carbon content and tensile strength of the steel under consideration and output the grade of the steel.

package assignment3;

import java.util.Scanner;

class Assigment3__1{

public static void main(String arg[]) {
float a = 0, b = 0, d = 0;
float grade ;

Scanner key = new Scanner(System.in);
System.out.print("Enter the value of Hardness=");
float h = key.nextInt();
System.out.print("Enter the value of Carbon content=");
float c = key.nextInt();
System.out.print("Enter the value of tensile Strength=");
float t = key.nextInt();


if (h > 50)
a = 1;

if (c < 0.7)
b = 1;

if (t > 5600)
d = 1;

if (a == 1 && b == 1 && d == 1)

System.out.println("grade 10");

else if (a == 1 && d == 0 && c == 1)

System.out.println("grade 9");

else if (b == 1 && a == 0 && d == 1)

System.out.println("grade 8");


else if (a == 1 && b == 0 && d == 1)

System.out.println("grade 7");

else if(a==1 || b==1 || c==1)



System.out.println("grade 6");

else


System.out.println("grade 5");




}
}
2. In a company, worker efficiency is determined on the basis of the time required for a worker to complete a particular job. If the time taken by the worker is between 2 3 hours, then the worker is said to be highly efficient.If the time required by the worker is between 3 4 hours, then the worker is ordered to improve speed. If the time taken is between 4 5 hours, the worker is given training to improve his speed, and if the time taken by the worker is more than 5 hours, then the worker has to leave the company. If the time taken by the worker is input through the keyboard, find the efficiency of the worker.


package assignment3;

import java.util.Scanner;

public class Assigment3_2 {
    public static void main(String arg[]){
    Scanner key=new Scanner(System.in);
        System.out.println("time taken by the worker is");
  float a= key.nextInt();
  if(a>=2 && a==3 ) {
      System.out.println("highly efficient");
  }


       if(a>3 && a==4 )
    {
        System.out.println("improve speed");
    }
       if(a>4 && a==5){
           System.out.println("improve his speed");
       }
       if(a>5)
       {
           System.out.println("leave the company");
       }
}
}


3. A university has the following rules for a student to qualify for a degree with A as the main subject and B as the subsidiary subject:

(a) He should get 55 percent or more in A and 45 percent or more in B.

(b) If he gets than 55 percent in A he should get 55 percent or more in B. However, he should get at least 45 percent in A.

(c) If he gets less than 45 percent in B and 65 percent or more in A he is allowed to reappear in an examination in B to qualify.

(d) In all other cases he is declared to have failed.

Write a program to receive marks in A and B and Output whether the student has passed, failed or is allowed to reappear in B


package assignment3;

import java.util.Scanner;

public class Assigment3_3 {
    public static void main(String arg[])
    {
        Scanner key=new Scanner(System.in);
        System.out.print("Enter the A and b Subject=");
        int a= key.nextInt();
        int b= key.nextInt();
if(a>=55 && b>=45)
{
    System.out.println("Student passed");
}
else if(a>=45 && a<55 && b>=55 ){
    System.out.println("Student passed");
}
else if(a>=66 &&b<45 )
{
    System.out.println(" reappear in an examination in B to qualify");
}
else
    System.out.println("student failed");
    }
}
Top 10 Java Questions Problems

4. The policy followed by a company to process customer orders is given by the following rules:

(a) If a customer order is less than or equal to that in stock and has credit is OK, supply has requirement.

(b) If has credit is not OK do not supply. Send him intimation.

(c) If has credit is Ok but the item in stock is less than has order, supply what is in stock. Intimate to him data the balance will be shipped.

package assignment3;

import java.util.Scanner;

public class Assigment3_4 {
public static void main(String arg[]) {


int stock = 100;
int credit;
Scanner key = new Scanner(System.in);
System.out.print("Enter the customer order=");
int order = key.nextInt();
System.out.print("credit confirmed press 1 and credit not confirmed press 2=");
int b=key.nextInt();

if(order<stock && b==1){
System.out.print("supply has requirement="+order);
}
else if (order>stock && b==1){
System.out.println("We supplied products and balance will be shipped later="+stock);
}
else
{
System.out.println("Please first clear your credit, until we can't supply you any more.");

}
}
}

5. Write a program to enter the numbers till the user wants and at the end it should display the count of positive, negative and zeros entered.

package assignment3;

import java.util.Scanner;

public class Assigment3_5 {
public static void main(String arg[]) {
Scanner key = new Scanner(System.in);
System.out.print("enter the any numbers=");
double a = key.nextInt();
if (a == 0) {
System.out.println("Zero");
}
if (a < 0) {
System.out.println("Negative");
}
if (a > 0) {
System.out.println("Positive");
}
}
}

System.out.print(“Enter the value of Hardness=”); float h = key.nextInt(); System.out.print(“Enter the value of Carbon content=”); float c = key.nextInt(); System.out.print(“Enter the value of tensile Strength=”); float t = key.nextInt(); if (h > 50) a = 1; if (c < 0.7) b = 1; if (t > 5600) d = 1; if (a == 1 && b == 1 && d == 1) System.out.println(“grade 10”); else if (a == 1 && d == 0 && c == 1) System.out.println(“grade 9”); else if (b == 1 && a == 0 && d == 1) System.out.println(“grade 8”); else if (a == 1 && b == 0 && d == 1) System.out.println(“grade 7”); else if(a==1 || b==1 || c==1) System.out.println(“grade 6”); else System.out.println(“grade 5”); } } //2. In a company, worker efficiency is determined on the basis of the time // required for a worker to complete a particular job. If the time taken by the // worker is between 2 – 3 hours, then the worker is said to be highly efficient. //If the time required by the worker is between 3 – 4 hours, then the worker is //ordered to improve speed. If the time taken is between 4 – 5 hours, the worker //is given training to improve his speed, and if the time taken by the worker is //more than 5 hours, then the worker has to leave the company. If the time taken //by the worker is input through the keyboard, find the efficiency of the worker. package assignment3; import java.util.Scanner; public class Assigment3_2 { public static void main(String arg[]){ Scanner key=new Scanner(System.in); System.out.println(“time taken by the worker is”); float a= key.nextInt(); if(a>=2 && a==3 ) { System.out.println(“highly efficient”); } if(a>3 && a==4 ) { System.out.println(“improve speed”); } if(a>4 && a==5){ System.out.println(“improve his speed”); } if(a>5) { System.out.println(“leave the company”); } }} //Write a program to receive marks in A and B and Output whether the student has passed, failed or is allowed to reappear in B. package assignment3; import java.util.Scanner; public class Assigment3_3 { public static void main(String arg[]) { Scanner key=new Scanner(System.in); System.out.print(“Enter the A and b Subject=”); int a= key.nextInt(); int b= key.nextInt(); if(a>=55 && b>=45) { System.out.println(“Student passed”); } else if(a>=45 && a<55 && b>=55 ){ System.out.println(“Student passed”); } else if(a>=66 &&b<45 ) { System.out.println(” reappear in an examination in B to qualify”); } else System.out.println(“student failed”); } } //4. The policy followed by a company to process customer orders is given by the following rules: // (a) If a customer order is less than or equal to that in stock and has credit is OK, supply has requirement. // (b) If has credit is not OK do not supply. Send him intimation. // (c) If has credit is Ok but the item in stock is less than has order, supply what is in stock. Intimate to him data the balance will be shipped. // Write a C program to implement the company policy. package assignment3; import java.util.Scanner; public class Assigment3_4 { public static void main(String arg[]) { int stock = 100; int credit; Scanner key = new Scanner(System.in); System.out.print(“Enter the customer order=”); int order = key.nextInt(); System.out.print(“credit confirmed press 1 and credit not confirmed press 2=”); int b=key.nextInt(); if(order<stock && b==1){ System.out.print(“supply has requirement=”+order); } else if (order>stock && b==1){ System.out.println(“We supplied products and balance will be shipped later=”+stock); } else { System.out.println(“Please first clear your credit, until we can’t supply you any more.”); } } } package assignment3; import java.util.Scanner; public class Assigment3_5 { public static void main(String arg[]) { Scanner key = new Scanner(System.in); System.out.print(“enter the any numbers=”); double a = key.nextInt(); if (a == 0) { System.out.println(“Zero”); } if (a < 0) { System.out.println(“Negative”); } if (a > 0) { System.out.println(“Positive”); } } }

I am Anmol gupta, i warmly welcome you to APNE KO JANO, and hope you liked this article, My mission is to inspire millions of people, i can show you the right path to go ahead.

Leave a Reply

Your email address will not be published. Required fields are marked *