Posts

Write a java program for a cricket player The program should accept the details from user (max 10): Player code, name, runs, innings- played and number of times not out.

Write a java program for a cricket player The program should accept the details from user (max 10): Player code, name, runs, innings- played and number of times not out. The program should contain following menu: -Enter details of players. -Display average runs of a single player. -Display average runs of all players. (Use array of objects & function overloading) import java.io.*; class Player { String Name; int TotalRuns, TimesNotOut, InningsPlayed,pcode; float Avg; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); void getData() { try { System.out.println("Enter Player Code: "); pcode=Integer.parseInt(br.readLine()); System.out.println("Enter Player Name: "); Name = br.readLine(); System.out.println("Enter Total Runs: "); Tot

Create a smiling and crying face alternet using Threading Mechenism

import java.awt.*; import java.applet.*; /* <applet code= "smileface.java" height="600" width="600"> </applet> */ public class smileface extends java.applet.Applet implements Runnable { int aflag; Thread t; public void init() { t=new Thread(this); aflag=0; t.start(); } public void run() { try { if (aflag==0) { t.sleep(1000); aflag=1; } else { t.sleep(1000); aflag=0; } repaint(); run(); } catch(Exception e) { } } public void paint(Graphics g) { g.drawOval(100,100,100,100); g.fillOval(120,125,20,20); g.fillOval(160,125,20,20); g.drawLine(150,135,150,165); if (aflag==0) { g.drawArc(140,160,20,20,0,-180); aflag=1; } else { g.drawArc(140,160,20,20,0,180); aflag=0; } } }

Write a MultiThreading program in java using Runnable interface to draw temple flag on an applet container.

import java.awt.*; import java.awt.event.*; class MoveText extends Frame implements Runnable { Label l1; Thread t; int x,y,side; public MoveText() { setLayout(null); l1=new Label(" Hello Java"); l1.setFont(new Font("",Font.BOLD,14)); l1.setForeground(Color.red); setSize(400,400); setVisible(true); t=new Thread(this); t.start(); x=5; y=200;side=1; addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); } public void run() { try { if(side==1) { t.sleep(50); l1.setBounds(x+=5,y-=5,70,15); add(l1); if(y==20) side=2; } if(side==2) { t.sleep(50); l1.setBounds(x+=5,y+=5,70,15); add(l1); if(y==200) side=3; } if(side==3) { t.sleep(50); l1.setBounds(x-=5,y+=5,70,15); add(l1); if(y==390)

C Program to display ASCII value of a Character, it's next character, and it's previous character.

#include<stdio.h> #include<conio.h> main() { char c; clrscr(); printf("Enter the character\n"); scanf("%c",&c); printf("\n The ASCII value of %c is %d",c,c); printf("\n Previous character of %c is %c",c,c-1); printf("\n Next Character of %c is %c",c,c+1); } OUTPUT : Enter the character s The ASCII value of s is 115 Previous character of s is r Next Character of s is t

Scanner in Java

Scanner is used in JAVA to accept the values from the user through the Standard I/O devices. Below is a basic program to demonstrate the use of scanner : import java.util.Scanner; public class scan { public static void main(String[] args) { Scanner s=new Scanner(System.in); System.out.println("Enter any string"); String a=s.nextLine(); System.out.println("String is :"+a); } }  OUTPUT : Enter any string codeground String is :codeground

Menu Driven C program to calculate Area of Square, Rectangle

This program demonstrates the use of switch() case : #include<stdio.h> #include<conio.h> #include<stdlib.h> main() { int ch; float s,l,b; float arect,asquare; clrscr(); do { printf("\t Main Menu\n"); printf("\t 1. Area of Rectangle.\n"); printf("\t 2. Area of Square.\n"); printf("\t 3. Exit\n"); printf("\n\tEnter your choice:\n"); scanf("%d",&ch); switch(ch) { case 1 : printf("\n\tEnter length and bredth:\n"); scanf("%f%f",&l,&b); arect=l*b; printf("\n\tArea of rectangle is : %f\n\n",arect); break; case 2 : printf("\n\tEnter side of the Square:\n"); scanf("%f",&s); asquare=s*s; printf("\n\tArea of Square is : %f\n\n",asquare); break; case 3 : exit(0); } }