You are on page 1of 8

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package getinputfromkeyboard;
/**
*
* @author AMA
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class GetInputFromKeyboard {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
BufferedReader dataIn=new BufferedReader (new InputStreamReader(System.in));
String name = "";
System.out.print("Please enter your name:");
try{
name = dataIn.readLine();
}catch(IOException e){
System.out.println("Error!");
}
System.out.println("Hello" + name + "!");
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package grades;
/**
*
* @author AMA
*/
import javax.swing.JOptionPane;
public class Grades {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
double firstGrade=0;
double secondGrade=0;
double thirdGrade=0;
double average=0;
try{
firstGrade=Double.parseDouble(JOptionPane.showInputDialog("First Grade"));
secondGrade=Double.parseDouble(JOptionPane.showInputDialog("Second Grade"));
thirdGrade=Double.parseDouble(JOptionPane.showInputDialog("Third Grade"));
}catch(Exception e){
JOptionPane.showMessageDialog(null,e.getMessage());
JOptionPane.showMessageDialog(null, "Input is Invalid");
System.exit(0);
}
average=(firstGrade+secondGrade+thirdGrade)/3;
if(average>=60)
{
JOptionPane.showMessageDialog(null,"Average"+average+";-)");
}
else
{
JOptionPane.showMessageDialog(null,"Average"+average+";-(");
}

}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package grades1;
/**
*
* @author AMA
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Grades1 {


/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
BufferedReader convert = new BufferedReader (new InputStreamReader (System.in));
double firstGrade=0;
double secondGrade=0;
double thirdGrade=0;
double average=0;
try{
System.out.println("Enter Num1:");
firstGrade=Double.parseDouble(convert.readLine());
System.out.println("Enter Num2:");
secondGrade=Double.parseDouble(convert.readLine());
System.out.println("Enter Num3:");
thirdGrade=Double.parseDouble(convert.readLine());
}catch(Exception e){
System.out.println ("Input is invalid");
System.exit(0);
}
average=(firstGrade+secondGrade+thirdGrade)/3;
if(average>=60)
{
System.out.println ("Average"+average+";-)");
}
else
{
System.out.println ("Average"+average+";-(");
}

}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package grades1;
/**

*
* @author AMA
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import javax.swing.JOptionPane;
public class Grades1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
BufferedReader convert = new BufferedReader (new InputStreamReader (System.in));
double firstGrade=0;
double secondGrade=0;
double thirdGrade=0;
double average=0;
try{
System.out.println("Enter Num1:");
firstGrade=Double.parseDouble(convert.readLine());
System.out.println("Enter Num2:");
secondGrade=Double.parseDouble(convert.readLine());
System.out.println("Enter Num3:");
thirdGrade=Double.parseDouble(convert.readLine());
}catch(Exception e){
System.out.println ("Input is invalid");
System.exit(0);
}
average=(firstGrade+secondGrade+thirdGrade)/3;
if(average>=60)
{
System.out.println ("Average"+average+";-)");
JOptionPane.showMessageDialog(null,"Average"+average+";-)");
}
else
{
System.out.println ("Average"+average+";-(");
JOptionPane.showMessageDialog(null,"Average"+average+";-(");
}

}
}

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mp2;
import java.io.IOException;
import java.util.Scanner;
/**
*
* @author AMA
*/
public class MP2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int num1=0, num2=0, num3=0;
Scanner mp = new Scanner (System.in);
System.out.println("Enter Num1:");
num1=mp.nextInt();
System.out.println("Enter Num2:");
num2=mp.nextInt();
System.out.println("Enter Num3:");
num3=mp.nextInt();

if ((num1>num2) && (num1>num3) && (num2>num3)){


System.out.println("Highest is"+num1);
System.out.println("Middle is" + num2);
System.out.println("Lowest is" + num3);
}
else if ((num1<num2) && (num2>num3) && (num1>num3)){
System.out.println("Highest is"+num2);
System.out.println("Middle is" + num1);
System.out.println("Lowest is" + num3);
}
else if ((num1<num3) && (num2<num3) && (num1<num2)){
System.out.println("Highest is"+num3);
System.out.println("Middle is" + num2);
System.out.println("Lowest is" + num1);
}

else if ((num1>num2) && (num2<num3) && (num1>num3)){


System.out.println("Highest is"+num1);
System.out.println("Middle is" + num3);
System.out.println("Lowest is" + num2);
}
else if ((num1<num2) && (num2>num3) && (num1<num3)){
System.out.println("Highest is"+num2);
System.out.println("Middle is" + num3);
System.out.println("Lowest is" + num1);
}
else if ((num1<num3) && (num2<num3) && (num1>num2)){
System.out.println("Highest is"+num3);
System.out.println("Middle is" + num1);
System.out.println("Lowest is" + num2);
}

}
}
int num = 1;
*while (num<=5)
{
System.out.print(num);
num++;
}
for (int ctr=1; ctr<=5; ctr++) {
System.out.print(ctr);
}

import java.util.Scanner;
public class TestWhileLoop {

/**
* @param args the command line arguments
*/

public static void main(String[] args) {


// TODO code application logic here
int num = 0, ctr = 0;
Scanner cholo = new Scanner (System.in);
System.out.print("Enter a Number:");
num = cholo.nextInt();
for (ctr=1; ctr<=num; ctr++) {
System.out.print(ctr + " ");
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication3;
/**
*
* @author AMA
*/
import java.util.Scanner;
public class JavaApplication3 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner cholo = new Scanner (System.in);
int num=0, ctr=1, total=1;
System.out.print("Enter a number: ");
num=cholo.nextInt();

for (ctr=1; ctr<=num; ctr++) {


for (total=1; total<=num; total++)
{
System.out.print(total*ctr + "\t");
}
System.out.println();

}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mp;
/**
*
* @author AMA
*/
import java.util.Scanner;
public class MP {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner mp = new Scanner (System.in);
int input=-1,b=0,c=0;
while (input!=0){
System.out.print("Enter a postive number: ");
input=mp.nextInt();
if (input>0){
c+=input;
System.out.println("Total= " +c);
}
}
System.out.println("Total= " +c);
System.out.print("Done");

}
}

You might also like