Category Uncategorized

One day Bob is playing Zombie World video game. In Zombie World game each round will contain N zombie’s and each zombie’s energy is Zi (where 1<=i<=N). Bob will start the round with B energy. In order to move to the next level Bob need to kill all the N zombie's but Bob can select any one among N Zombie's. If energy of Bob (B) is less than Zombie energy (Zi) then Bob will die and lose the round else Bob will won, during the fighting with zombie, Bob will lose his energy by (Zi%2)+(Zi/2). At any point of game Bob will play optimally. Now your task is to find out whether Bob can reach to the next level or not.

Input Format: First line will contains B and N, separated by space, where B is the energy of Bob and N is the number of Zombie. Next line will contain N spaced integers each will represent the energy of zombie. Line 1 B N, where B is the energy of Bob and N…

Write a Java program that checks whether a given string is a palindrome or not. Ex: MADAM is a palindrome.

//Program to check whether the given string is palindrome or not import java.util.*; class Palindrome {             public static void main(String args[])             {                         String str;                         int flag=0;                         Scanner scr=new Scanner(System.in);                         System.out.println(“nEnter any String:”);                         str=scr.next();…

Write a java program to create an abstract class named Shape that contains an empty method named numberofSides ( ).Provide three classes named Trapezoid, Triangle and Hexagon such that each one of the classes extends the class Shape. Each one of the classes contains only the method numberofSides ( ) that shows the number of sides in the given geometrical figures.

  Output:   Number of sides of Trapeziod is : 4 Number of sides of Triangle is : 3   Number of sides of Hexagon is : 6

Write a java program that implements a simple/client application. That client sends data to a server. The server receives the data, Uses it to produce a result, and then sends the result back to the client. The client displays the result on the console. For ex: The data sent from the client is the radius of a circle, and the result produced by the server is the area of the circle(Use java.net)

//Program for implementing Server/Client Application // Server Program import java.io.*; import java.net.*; class Server {             public static void main(String args[])             {                         try                         {                                     ServerSocket ss=new ServerSocket(1064);                                     System.out.println(“Waiting for Client Request”);                                     Socket s=ss.accept();                                    …

Write a Program for Handling Mouse events

//Program to implement mouse events import java.awt.*; import java.awt.event.*; import java.applet.*; public class Mouseevents extends Applet implements MouseListener,MouseMotionListener {             /*<applet code=”Mouseevents” width=500 height=300></applet>*/             String msg=””;             int mousex=0,mousey=0;             public void init()             {                         addMouseListener(this);                         addMouseMotionListener(this);…

Write a Java program that works as a simple calculator. Use a grid layout to arrange buttons for the digits and for the +, -,*, % operations. Add a text field to display the result.

//Program for implementing a Simple Calculator import java.awt.*; import java.awt.event.*; import java.applet.*; /*<applet  code=”Calculator1″ width=300 height=300></applet>*/ public class Calculator1 extends Applet implements ActionListener {             TextField t;                 Button b[]=new Button[15];             Button b1[]=new Button[6];             String op2[]={“+”,”-“,”*”,”%”,”=”,”C”};             String…

Write a java program evaluates the postfix expression

//Evaluating the postfix expression import java.util.*; class postfix1 {             double a[]=new double[20];             int top;             postfix1() { top=-1; }                         void push(double x)             {                                  top++;                         a[top]=x;             }                         double pop()             {…

Write a java program Converts infix expression into Postfix form

//Program for infix to postfix conversion import java.util.*; class itop1 {             char s[]=new char[10];             int top;             itop1() {top=-1; }                         void i2post(char in[])             {                         int i,j=0;                         char post[]=new char[20];                         char ichar,schar;                        …

Write a Java program that Implements stack ADT.

//Program to implement Stacks import java.util.*; import java.io.*; class Stack1 {             int t;             int a[]=new int[5];             Stack1()             {                         t=-1;             }             boolean isempty()             {                         return (t==-1);             }             boolean isfull()            …

Write a Java program that Implements stack ADT.

//Program to implement Stacks import java.util.*; import java.io.*; class Stack1 {             int t;             int a[]=new int[5];             Stack1()             {                         t=-1;             }             boolean isempty()             {                         return (t==-1);             }             boolean isfull()            …

Write a Java program that displays the number of characters, lines and words in a text file.

//Program to count number of lines,characters,and words in a text file import java.util.*; import java.io.*; class Cfile {             public static void main(String args[])throws IOException             {                         int nl=1,nw=0;                                    char ch;                         Scanner scr=new Scanner(System.in);                        …

Write a Java program that reads a file and displays the file on the screen, with a line number before each line.

//Program to print the contents of the file along with line number import java.util.*; import java.io.*; class Rfile {             public static void main(String args[])throws IOException             {                         int j=1;                         char ch;                         Scanner scr=new Scanner(System.in);…

(Using java.lang.FileInputStream and FileOutputStream) a) Write a Java program that reads a file name from the user, then displays information about whether the file exists, whether the file is readable, whether the file is writable, the type of file and the length of the file in bytes.

//Program to read a file and display its properties import java.io.*; import java.util.*; import javax.swing.*; class Fileproperties {             public static void main(String args[])throws IOException             {                         Scanner scr=new Scanner(System.in);                         System.out.print(“nEnter any file name: “);                         String str=scr.nextLine();…

Write a Java Program that reads a line of integers, and then displays each integer, and the sum of all the integers (Use StringTokenizer class of java.util)

//Program to print the read numbers and find sum import java.util.*; class Sumtoken {             public static void main(String args[])             {                         Scanner scr=new Scanner(System.in); System.out.println(“nEnter sequence of integers with space b/w them and press enter : “);                        …

Enable Notifications OK No thanks