Você está na página 1de 3

JAVA Assignment 1

Shoaib Farooq
============================================
Q1

class Print{
public static void main(String a[]){
System.out.println("Name : Usman Aftab");
System.out.println("Address: House # 2,Street # 1,Model
Town");
}
}

Q2

class Variable{
public static void main(String a[]){
float num1=14f;
float num2=9f;
float sum=0f;
float avg=0f;

sum=num1+num2;
avg=(num1+num2)/2;

System.out.println("Sum: "+sum);
System.out.println("Average: "+avg);
}
}
Q3

import java.util.*;
import javax.swing.*;

class Coins{
public static void main(String a[]){
int
rupees=Integer.parseInt(JOptionPane.showInputDialog("Enter
Money: "));

int five=0;
int two=0;
int one=0;
int count=0;
int count1=0;

for(int i=1;i<=rupees;i++){
if(i%5==0){
five++;
count=i;
}
}

if(count<rupees){
for(int j=count+1;j<=rupees;j++){
if(j%2==0){
two++;
count1=j;
}
}
}
else
count1=count;

for(int k=count1+1;k<=rupees;k++)
one++;

System.out.println("5 Coins: "+five);


System.out.println("2 Coins: "+two);
System.out.println("1 Coins: "+one);
}
}

Q4

import java.util.*;
import javax.swing.*;

class Chocolate{
public static void main(String a[])throws Exception{

int
totalChocolates=Integer.parseInt(JOptionPane.showInputDialog("E
nter Total Chocolates: "));
int
weight=Integer.parseInt(JOptionPane.showInputDialog("Enter
weight of one Chocolates in Ounces: "));

char choice;
System.out.println("Enter a character");
choice = (char)System.in.read();

if(choice == 'o' || choice == 'O'){


int totalOunces;
totalOunces=totalChocolates*weight;
System.out.println(totalOunces);
}
else if(choice == 'p' || choice == 'P'){
float totalPounds=0f;
totalPounds=(float)(totalChocolates*weight)/16;
System.out.println(totalPounds);
}
}
}

http://www.ravianeducation.blogspot.com
FARHAN: 03008855006

Você também pode gostar