Showing posts with label While. Show all posts
Showing posts with label While. Show all posts
Sunday, 30 March 2014
JAVA PROGRAMS-Student Details Program in Java
Student Details Program in Java
Program Name:- student1.java
import java.io.*;
class studentdetail
{
int sno;
String sname,major,yos;
void getdata()throws IOException
{
DataInputStream in=new DataInputStream(System.in);
System.out.print("\n Enter the student number\t:");
sno=Integer.parseInt(in.readLine());
System.out.print("\n Enter the student name\t:");
sname=in.readLine();
System.out.print("\n Enter the student Major\t:");
major=in.readLine();
System.out.print("\n Enter the year of student\t:");
yos=in.readLine();
}
}
class markdetails extends studentdetail
{
int m1,m2,m3,m4,tot;
String res;
void read()throws IOException
{
DataInputStream in=new DataInputStream(System.in);
getdata();
System.out.print("\n Enter the mark1\t:");
m1=Integer.parseInt(in.readLine());
System.out.print("\n Enter the mark2\t:");
m2=Integer.parseInt(in.readLine());
System.out.print("\n Enter the mark3\t:");
m3=Integer.parseInt(in.readLine());
System.out.print("\n Enter the mark4\t:");
m4=Integer.parseInt(in.readLine());
}
void total()
{
tot=m1+m2+m3+m4;
}
void result()
{
if((m1>=50)&&(m2>=50)&&(m3>=50)&&(m4>=50))
res="Pass";
else
res="Fail";
}
void display()
{
System.out.println("\n\n \t Student details \n\n");
System.out.println("\n Student number\t:"+sno);
System.out.println("\n Student name\t:"+sname);
System.out.println("\n Student major\t:"+major);
System.out.println("\n Year of Study\t:"+yos);
System.out.print("\n mark1: \t"+m1+"\n\n mark2: \t"+m2+"\n\n mark3: \t"+m3+"\n\n mark4: \t"+m4);
System.out.print("\n\n Total: \t"+tot+"\n\n Result: "+res);
}
}
class student1
{
public static void main(String[]args)throws IOException
{
markdetails in=new markdetails();
in.read();
in.total();
in.result();
in.display();
}
}
Labels:
-,
Details,
In,
java,
java code,
java programs,
JAVA PROGRAMS-Student Details Program in Java,
Program,
program in java,
PROGRAMS,
Student,
Ternary Loops programs in Java,
w3 java,
w3 schools,
While
JAVA PROGRAMS-For,While,Do-While,Ternary Loops programs in Java
For,While,Do-While,Ternary Loops programs in Java
Program Name:- simplepgm2
import java.io.*;
class simplepgm
{
void for_fun()
{
System.out.println("Enter the value ");
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.println(""+j);
}
System.out.println("\n");
}
}
void while_fun()
{
int a=0,b=1,c=1;
System.out.println("Fibonacci series");
System.out.println(a+"\n"+b+"\n");
while(c<=0)
{
int f=a+b;
System.out.println(f+"\n");
c+=1;
a=b;
b=f;
}
}
void dowhile_fun()
{
int sum=0,i=1;
do
{
sum=sum+i;
i+=1;
}
while(i<=10);
System.out.println("sum="+sum);
}
void ternary_fun()
{
int a=10,b=15,c=5;
int x=(a>b&&a>c)?a:(b>c)?b:c;
System.out.println(x+" is big");
}
}
class simplepgm2
{
public static void main(String arg[])throws IOException
{
char choice;
simplepgm obj=new simplepgm();
do
{
System.out.println("\n 1.For funtion");
System.out.println("\n 2.While funtion");
System.out.println("\n 3.do while funtion");
System.out.println("\n 4.Ternary funtion");
choice=(char)System.in.read();
}while(choice<'1'||choice>'8');
switch(choice)
{
case '1':
obj.for_fun();
break;
case '2':
obj.while_fun();
break;
case '3':
obj.dowhile_fun();
break;
case '4':
obj.ternary_fun();
break;
default:
System.out.println("not current choice");
}
}
}
Subscribe to:
Posts (Atom)