0% found this document useful (0 votes)
22 views3 pages

Simple Programs

Simple Java programs for conditional and looping statements
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

Simple Programs

Simple Java programs for conditional and looping statements
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.io.

*;
public class IfDemo
{
public static void main(String a[])
{
int i = -7;
if(i<0)
System.out.println("Negative");
}
}
----------------------
import java.io.*;
public class IfElseDemo
{
public static void main(String args[])
{
int a = 5;
int b = 15;
if(a > b)
{
System.out.println(a+" is bigger");
}
else
{
System.out.println(b+" is bigger");
}
}
}
-------------------------
import java.io.*;
public class IfElseIfDemo
{
public static void main(String args[])
{
int a = 25;
int b = 35;
int c = 27;
if( a > b)
{
if( a > c)
{
System.out.print(a+" is biggest");
}
else
{
System.out.print(c + " is biggest");
}
}
else if( b > c)
{
System.out.print(b +" is biggest");
}
else
{
System.out.print(c + " is biggest");
}

}
}
-----------------
WhileDemo.java
import java.io.*;
public class WhileDemo
{
public static void main(String args[])
{
int i=1;
while(i<=10)
{
System.out.println(i);
i++;
}
}
}
--------------------------
import java.io.*;
public class DoDemo
{
public static void main(String args[])
{
int i=1;
do
{
System.out.println(i);
i++;
}while(i<=10);
}
}
-------------------
import java.io.*;
public class ArrayDemo
{
public static void main(String args[])
{
int i;
int a[5]={1,3,5,6,12};
int sum=0;
for(i=0;i<5;i++)
{
System.out.println(a[i]);
sum += a[i];
}
System.out.println(sum);
}
}
------------------
import java.util.*;
class Student
{
int regno;
String name;
int m[3],total;
void readInput()
{
Scanner s= new Scanner(System.in);
System.out.print("Enter Register number : ");
regno = s.nextInt();
System.out.print("Enter Name : );
name = s.nextLine();
System.out.print("Enter Marks for 3 Subjects :");
for(int i=0;i<3;i++)
m[i] = s.nextInt();
total +=m[i];
}
void display()
{
System.out.println("Register Number : "+ regno);
System.out.println("Name : "+name);
System.out.println("Total : "+total);
}

}
public class Mark
{
public static void main(String args[])
{
Student s;
s = new Student();
s.readInput();
s.display();
}
}

You might also like